pango99
驱动牛犊
驱动牛犊
  • 注册日期2001-08-21
  • 最后登录2018-05-29
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望20点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1180回复:2

我VC++写了个动态调用WDM的类(即用NTSERVICE方法),可老出现997错误(重叠 I/O 操作在进行中),现将代码

楼主#
更多 发布于:2001-12-17 18:35
// 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);
}
guardee
驱动巨牛
驱动巨牛
  • 注册日期2002-11-08
  • 最后登录2010-05-29
  • 粉丝2
  • 关注1
  • 积分2分
  • 威望34点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2001-12-20 12:54
你的这个997错误是调用了什么函数出现的啊?是不是调用了 dviceIoControl之后他的返回值是997啊?
pango99
驱动牛犊
驱动牛犊
  • 注册日期2001-08-21
  • 最后登录2018-05-29
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望20点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2001-12-21 12:41
是在调用了StartService()后出现的
游客

返回顶部