阅读:1586回复:6
动态加载的问题
第一次运行时老是会出错
说“could not create service” 第二次运行也会出这样的错 但是按了对话框的“确定”后 程序还是能正常运行 源代码如下: BOOL LoadDeviceDriver( const TCHAR * Name, const TCHAR * Path, HANDLE * lphDevice, PDWORD Error ) { SC_HANDLE SCManagerHandle; SC_HANDLE SCServiceHandle; BOOL status; SCManagerHandle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS ); if(SCManagerHandle==NULL) { MessageBox(NULL,TEXT(\"Could not open SC\"),NULL,MB_OK); return FALSE; }else{ SCServiceHandle = CreateService( SCManagerHandle, // SCManager database Name, // name of service Name, // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_KERNEL_DRIVER, // service type SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type Path, // service\'s binary NULL, // no load ordering group NULL, // no tag identifier NULL, // no dependencies NULL, // LocalSystem account NULL // no password ); if ( SCServiceHandle == NULL ) { MessageBox(NULL,TEXT(\"Could not create service!\"),NULL,MB_OK); } CloseServiceHandle( SCServiceHandle ); SCServiceHandle=OpenService(SCManagerHandle,Name,SERVICE_START); if(SCServiceHandle==NULL) { MessageBox(NULL,TEXT(\"Could not open service!\"),NULL,MB_OK); } status=StartService(SCServiceHandle,0,NULL); if(!status){ if(GetLastError()==ERROR_SERVICE_ALREADY_RUNNING){ return TRUE; } } status = OpenDevice( Name, lphDevice ); *Error = GetLastError(); CloseServiceHandle( SCManagerHandle ); return status; } } |
|
沙发#
发布于:2003-05-04 22:15
SCServiceHandle = CreateService( SCManagerHandle, // SCManager database
Name, // name of service Name, // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_KERNEL_DRIVER, // service type SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type Path, // service\'s binary NULL, // no load ordering group NULL, // no tag identifier NULL, // no dependencies NULL, // LocalSystem account NULL // no password ); if ( SCServiceHandle == NULL ) { MessageBox(NULL,TEXT(\"Could not create service!\"),NULL,MB_OK); } 这里检查是不是ERROR_SERVICE_EXISTS if ( SCServiceHandle == NULL ) { if GetLadtError() != ERROR_SERVICE_EXISTS //... MessageBox(NULL,TEXT(\"Could not create service!\"),NULL,MB_OK); } 可能的原因。 |
|
板凳#
发布于:2003-05-05 10:42
这样改了之后还是不稳定,
总是一次可以正常运行, 下一次就不行了,会出现“could not create service” 再下一次又可以了。 我想是不是因为第一次成功地CreateService了一个服务, 在没有重启的情况下,第二次再CreateService一个同名服务就失败了。但是每次关掉应用程序时,驱动都会被卸载的。 |
|
地板#
发布于:2003-05-05 11:55
if ( SCServiceHandle == NULL )
{ DWROD rt = GetLastError(); if (rt != ERROR_SERVICE_EXISTS) { MessageBox(NULL,TEXT(\"Could not create service!\"),NULL,MB_OK); return FALSE; } } 在没有重启的情况下,第二次再CreateService一个同名服务就失败了。 不是检查ERROR_SERVICE_EXISTS了吗?单步跟一下看看哪个地方的问题,分析一下。 |
|
地下室#
发布于:2003-05-06 10:14
这样改了之后还是不稳定, 改成这样试试 ...... if ( SCServiceHandle == NULL ) { DWROD rt = GetLastError(); if (rt != ERROR_SERVICE_EXISTS) { SCServiceHandle=OpenService(SCManagerHandle,Name,SERVICE_ALL_ACCESS); if(!SCServiceHandle) return FALSE; } else return FALSE; } } status=StartService(SCServiceHandle,0,NULL); CloseServiceHandle(SCManagerHandle); } |
|
5楼#
发布于:2003-05-06 16:17
看看这个吧,也是动态加载的问题
http://www.driverdevelop.com/forum/html_39928.html?1052208952 怎么就没人理我啊,严重郁闷 |
|
6楼#
发布于:2004-10-16 11:03
我给你顶一下!
|
|