加载:
#define DEV_KEY TEXT("Drivers\\Builtin\\WCDMA") BOOL CGPRSCTRLDlg::Load() { //DWORD dwParam = 89; //HANDLE hd = ActivateDeviceEx(DEV_KEY,NULL,0,&dwParam); HANDLE hd = ActivateDeviceEx(DEV_KEY,NULL,,NULL); if(INVALID_HANDLE_VALUE==hd) { return FALSE; } else { return TRUE; } }
卸载:
BOOL CGPRSCTRLDlg::Unload(const wstring &strDev) { BOOL bRes = FALSE; HANDLE hFind = INVALID_HANDLE_VALUE; __try { if(strDev.empty() != FALSE) { RETAILMSG(DEBUGMESSAGE, (TEXT("[CGPRSCTRLDlg] Unload leave1\r\n"))); __leave; } //确定搜索的方式 DeviceSearchType searchType; ] == ':') { searchType = DeviceSearchByLegacyName; } else { searchType = DeviceSearchByDeviceName; } DEVMGR_DEVICE_INFORMATION devInfo = {}; devInfo.dwSize = sizeof(devInfo); //寻找驱动的句柄 hFind = FindFirstDevice(searchType,strDev.c_str(),&devInfo); if(hFind == INVALID_HANDLE_VALUE) { RETAILMSG(DEBUGMESSAGE, (TEXT("[CGPRSCTRLDlg] Unload leave2\r\n"))); __leave; } //卸载驱动 bRes = DeactivateDevice(devInfo.hDevice); RETAILMSG(DEBUGMESSAGE, (TEXT("[CGPRSCTRLDlg] DeactivateDevice\r\n"))); } __finally { FindClose(hFind); } return bRes; }
调用:
//加载 Load(); //卸载 Unload(_T("COM6:"));