|
我写了一个驱动程序,在使用的时候用以下代码:
SC_HANDLE hServiceMgr, hServiceTwdm;
BOOL bRtn;
DWORD dwRtn, dwSize = 256;
char szDir[256];
GetCurrentDirectory( dwSize, szDir );//取当前目录
strcat(szDir, "\\HelloWord.sys" ); //取驱动程序的全路径
LPCTSTR lpszBinaryPathName = TEXT(szDir);
hServiceMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS ); //打开服务控制管理器
if (NULL == hServiceMgr)
return 0;
hServiceTwdm = CreateService(hServiceMgr,
TEXT("Hello"),
TEXT("Helloword"), // 注册表驱动程序的 DisplayName 值
SERVICE_ALL_ACCESS, // 加载驱动程序的访问权限
SERVICE_KERNEL_DRIVER,// 表示加载的服务是驱动程序
SERVICE_DEMAND_START, // 注册表驱动程序的 Start 值
SERVICE_ERROR_IGNORE, // 注册表驱动程序的 ErrorControl 值
lpszBinaryPathName, // 注册表驱动程序的 ImagePath 值
NULL,
NULL,
NULL,
NULL,
NULL);
if (NULL == hServiceTwdm)
{
dwRtn = GetLastError();
if( dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_EXISTS )
{
CloseServiceHandle( hServiceMgr );
printf( "CrateService() Faild %d ! \n", dwRtn );
return 0;
}
}
hServiceTwdm = OpenService(hServiceMgr, TEXT("FirstMyDriver"), SERVICE_ALL_ACCESS);
if (NULL == hServiceTwdm)
{
CloseServiceHandle( hServiceMgr );
return 0;
}
BOOL bRet = StartService(hServiceTwdm, NULL, NULL );
if( !bRtn )
{
dwRtn = GetLastError();
if( dwRtn != ERROR_IO_PENDING && dwRtn != ERROR_SERVICE_ALREADY_RUNNING )
{
printf( "StartService() Faild %d ! \n", dwRtn );
CloseServiceHandle( hServiceTwdm );
CloseServiceHandle( hServiceMgr );
return 0;
}
else
{
if( dwRtn != ERROR_IO_PENDING )
{
printf( "StartService() Faild ERROR_IO_PENDING ! \n");
}
else
{
printf( "StartService() Faild ERROR_SERVICE_ALREADY_RUNNING ! \n");
}
}
}
当执行StartService的时候,电脑出现蓝屏,后来电脑就没有反应了,像是死机,可是电源灯是亮的,请各位高手帮我一下,我使用操作系统是XP,+ DDK200
|
|