BUILD: [01:0000000052:ERRORE] Restart.obj : error LNK2019: unresolved external symbol "int __cdecl KernelIoControl(unsigned long,void *,unsigned long,void *,unsigned long,unsigned long *)"
重启:KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
关机:SetSystemPowerState(NULL, POWER_STATE_OFF, POWER_FORCE);
待机:GwesPowerOffSystem();
#include <windows.h> #include "winioctl.h" BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned); #define IOCTL_HAL_GET_DEVICE_INFO CTL_CODE(FILE_DEVICE_HAL, 1, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_HAL_COLDBOOT CTL_CODE(FILE_DEVICE_HAL, 30, METHOD_BUFFERED, FILE_ANY_ACCESS)
void WINAPI Reboot (int nBootMode) { int inVal; BYTE outBuf[1024]; DWORD bytesReturned; //KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL)
if(nBootMode == 0) KernelIoControl(IOCTL_HAL_REBOOT, &inVal, 4, outBuf, 1024, &bytesReturned); //热启动 else KernelIoControl(IOCTL_HAL_COLDBOOT, &inVal, 4, outBuf, 1024, &bytesReturned); //冷启动 }
在PB工程里编译会出现错误,需加上头文件:extern "C" __declspec(dllimport)
extern "C" __declspec(dllimport) BOOL KernelIoControl( DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
extern "C" __declspec(dllimport) BOOL InterruptInitialize( DWORD idInt, HANDLE hEvent, LPVOID pvData, DWORD cbData );
问题解决,参考链接:
http://www.itlisting.org/4-windows-ce-embedded/b58c1716e8284c19.aspx