WinIo內有提供32bit/64bit的WinIo32.sys與WinIo64.sys,至於DLL、LIB則需要下載程式碼自行編譯來產生。
以下舉DLL靜態連結、動態連結與WinIo32.sys使用來對CMOS讀取。
CMOS資料夾內容靜態DLL連結
直接引用 "winio.h" 所以可以直接使用WinIo.h中的函數,這跟動態DLL連結最大的不同
#include "stdafx.h"
#include "winio.h"
#if defined(_WIN64)
#pragma comment(lib, "64/WinIo")//64/WinIo裡面存放64bit WinIo.lib
#elif defined(_WIN32)
#pragma comment(lib, "32/WinIo")//32/WinIo裡面存放32bit WinIo.lib
#endif
int main(int argc, TCHAR* argv[])
{
BOOL bRet = FALSE;
DWORD dwTemp = 0;
bRet = InitializeWinIo();
if (!bRet)
{
printf("Error during initialization of WinIo. %08X\n", GetLastError());
return bRet;
}
SetPortVal(0x70, atoi(argv[1]), 1);
GetPortVal(0x71, &dwTemp, 1);
printf("%08X\n", dwTemp);
bRet = RemoveWinIoDriver();
ShutdownWinIo ();
return bRet;
}
執行結果
動態DLL連結
可不需要引用 "winio.h" 即可使用WinIo.h中的函數,但要知道DLL存放位置
#include "stdafx.h"
typedef bool (WINAPI * DLL_InitializeWinIo)();
DLL_InitializeWinIo InitializeWinIo;
typedef bool (WINAPI * DLL_RemoveWinIoDriver)();
DLL_RemoveWinIoDriver RemoveWinIoDriver;
typedef void (WINAPI * DLL_ShutdownWinIo)();
DLL_ShutdownWinIo ShutdownWinIo;
typedef bool (WINAPI * DLL_GetPortVal)(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
DLL_GetPortVal GetPortVal;
typedef bool (WINAPI * DLL_SetPortVal)(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
DLL_SetPortVal SetPortVal;
int main(int argc, TCHAR* argv[])
{
BOOL bRet = FALSE;
DWORD dwTemp = 0;
HINSTANCE hDLL;
#if defined(_WIN64)
hDLL = GetModuleHandle("WinIo64.dll");
if(hDLL == NULL)
hDLL = LoadLibrary("WinIo64.dll");
#elif defined(_WIN32)
hDLL = GetModuleHandle("WinIo32.dll");
if(hDLL == NULL)
hDLL = LoadLibrary("WinIo32.dll");
#endif
if (hDLL == NULL)
{
printf("Error load winio.dll fail. %08X\n", GetLastError());
return FALSE;
}
InitializeWinIo = (DLL_InitializeWinIo)GetProcAddress(hDLL, ("InitializeWinIo"));
if (!InitializeWinIo)
{
// handle the error
printf("Error InitializeWinIo fail. %08X\n", GetLastError());
FreeLibrary(hDLL);
return FALSE;
}
RemoveWinIoDriver = (DLL_RemoveWinIoDriver)GetProcAddress(hDLL, ("RemoveWinIoDriver"));
if (!RemoveWinIoDriver)
{
// handle the error
printf("Error RemoveWinIoDriver fail. %08X\n", GetLastError());
FreeLibrary(hDLL);
return FALSE;
}
ShutdownWinIo = (DLL_ShutdownWinIo)GetProcAddress(hDLL, ("ShutdownWinIo"));
if (!ShutdownWinIo)
{
// handle the error
printf("Error ShutdownWinIo fail. %08X\n", GetLastError());
FreeLibrary(hDLL);
return FALSE;
}
GetPortVal = (DLL_GetPortVal)GetProcAddress(hDLL, ("GetPortVal"));
if (!GetPortVal)
{
// handle the error
printf("Error GetPortVal fail. %08X\n", GetLastError());
FreeLibrary(hDLL);
return FALSE;
}
SetPortVal = (DLL_SetPortVal)GetProcAddress(hDLL, ("SetPortVal"));
if (!SetPortVal)
{
// handle the error
printf("Error SetPortVal fail. %08X\n", GetLastError());
FreeLibrary(hDLL);
return FALSE;
}
bRet = InitializeWinIo();
if (!bRet)
{
printf("Error during initialization of WinIo. %08X\n", GetLastError());
FreeLibrary(hDLL);
return bRet;
}
SetPortVal(0x70, atoi(argv[1]), 1);
GetPortVal(0x71, &dwTemp, 1);
printf("%08X\n", dwTemp);
bRet = RemoveWinIoDriver();
ShutdownWinIo ();
FreeLibrary(hDLL);
return bRet;
}
執行結果



沒有留言:
張貼留言