阅读:1179回复:2
我VC++写了个动态调用WDM的类(即用NTSERVICE方法),可老出现997错误(重叠 I/O 操作在进行中),现将代码
// SysDriver.cpp: implementation of the CSysDriver class.
// ////////////////////////////////////////////////////////////////////// #include \"stdafx.h\" #include \"SysDriver.h\" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CSysDriver::CSysDriver() { hDevice=NULL; } CSysDriver::~CSysDriver() { if(hDevice) UnloadDriver(); } BOOL CSysDriver::LoadDriver(LPCTSTR psDeviceName, LPCTSTR psFileName) { SC_HANDLE schMagr=NULL; SC_HANDLE schDevice=NULL; ZeroMemory(szService,sizeof(szService)); CopyMemory(szService,psDeviceName,strlen(psDeviceName)); char szDevice[100]; wsprintf(szDevice,\"\\\\\\\\.\\\\%s\\0\",psDeviceName); //unload precious driver UnloadDriver(); //load new driver; schMagr=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); if(schMagr==NULL) { goto over; } schDevice=CreateService(schMagr,TEXT(psDeviceName),TEXT(psDeviceName),SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,SERVICE_ERROR_IGNORE,TEXT(psFileName),NULL,NULL,NULL,NULL,NULL); if(schDevice==NULL) { goto over; } if(!StartService(schDevice,NULL,NULL)) { goto over; } hDevice=CreateFile(szDevice, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if(hDevice==INVALID_HANDLE_VALUE) { hDevice=NULL; goto over; }; over: if(schDevice) CloseServiceHandle(schDevice); if(schMagr) CloseServiceHandle(schMagr); return (hDevice)?TRUE:FALSE; } BOOL CSysDriver::UnloadDriver() { SC_HANDLE schMagr=NULL,schDevice=NULL; SERVICE_STATUS status; BOOL ret=FALSE; schMagr=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); if(schMagr==NULL) goto over; schDevice=OpenService(schMagr,TEXT(szService),SERVICE_ALL_ACCESS); if(schDevice==NULL) goto over; ControlService(schDevice,SERVICE_CONTROL_STOP,&status); DeleteService(schDevice); if(hDevice) CloseHandle(hDevice); hDevice=NULL; ret=TRUE; over: if(schDevice) CloseServiceHandle(schDevice); if(schMagr) CloseServiceHandle(schMagr); return ret; } BOOL CSysDriver::DeviceIoControl(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD dwInBufferLen, LPVOID lpOutBuffer, DWORD dwOutBufferLen, LPDWORD lpReturn, LPOVERLAPPED lpOverlapped) { return ::DeviceIoControl(hDevice,dwIoControlCode, lpInBuffer,dwInBufferLen, lpOutBuffer,dwOutBufferLen, lpReturn, lpOverlapped); } |
|
沙发#
发布于:2001-12-20 12:54
你的这个997错误是调用了什么函数出现的啊?是不是调用了 dviceIoControl之后他的返回值是997啊?
|
|
板凳#
发布于:2001-12-21 12:41
是在调用了StartService()后出现的
|
|