| 
			 
					阅读:1482回复:13
				 
				动态卸载出错
					我的驱动是windowsxp下用windowsxp ddk编译的
 
							动态加载成功,但是动态卸载时失败,返回0 GetLastError返回的错误码: 1052L ERROR_INVALID_SERVICE_CONTROL 请求的控件对此服务无效 我用的卸载函数是ControlService(m_sService,SERVICE_CONTROL_STOP,&Service_Status); 对么?驱动的unload例程也没有被调用 代码如下 m_sService = CreateService(...)//成功 m_sService = OpenService(..., SERVICE_ALL_ACCESS);//成功 StartService(m_sService, 0, NULL);//成功 。。。。。。。。。。。。。。//Createfile等操作 成功 ControlService(m_sService,SERVICE_CONTROL_STOP,&Service_Status);//失败!!! 返回 0 1052L ERROR_INVALID_SERVICE_CONTROL 请求的控件对此服务无效 大家帮忙看看 谢谢!!! [编辑 - 1/10/05 by nimingren]  | 
	|
| 
			 沙发# 
								发布于:2005-01-10 17:49				
			
					你用StartService启动服务之后,看看服务是否真的运行了
 
							bResult = WaitForState(SERVICE_RUNNING, &serviceStatus);  | 
	|
					
						
  | 
	
| 
			 板凳# 
								发布于:2005-01-10 17:51				
			
					具体出错原因可以用SoftIce+DriverVerifier得到,跟踪试试,很灵的^_^				 
							 | 
	|
					
						
  | 
	
| 
			 地板# 
								发布于:2005-01-10 18:41				
			
					谢谢 楼上两位大哥
 
							StartService 后我用调用DeviceIoCtrol 得到了响应 应该是启动了吧 SoftIce+DriverVerifier 咋用啊 我是第一次作驱动 我的驱动就是为了进入ring0 不是真的要控制硬件  | 
	|
| 
			 地下室# 
								发布于:2005-01-11 08:59				
			谢谢 楼上两位大哥 这个问题本身不复杂的,你还是好好检查一下吧。  | 
	|
					
						
  | 
	
| 
			 5楼# 
								发布于:2005-01-11 09:00				
			
					把你驱动贴出来看看.				 
							 | 
	|
					
						
  | 
	
| 
			 6楼# 
								发布于:2005-01-11 15:16				
			
					大侠们帮忙看看  
 
							exe 代码: #include <stdio.h> #include <io.h> #include "windows.h" #include <string> using namespace std; int main() { string strDeviceName="MyFunc11c"; char path[256]=""; GetSystemDirectory(path, 256); string strDriverName=path; strDriverName += "\\drivers\\"; strDriverName += "wdm11c.sys"; SERVICE_STATUS Service_Status; SC_HANDLE m_sManager= OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); SC_HANDLE m_sService = CreateService( m_sManager, strDeviceName.c_str(), strDeviceName.c_str(), SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, strDriverName.c_str(), NULL, NULL, NULL, NULL, NULL); m_sService = OpenService(m_sManager, strDeviceName.c_str(), SERVICE_ALL_ACCESS); if (StartService(m_sService, 0, NULL) == 0) { printf("start fail\n"); } Sleep(1000); int i = ControlService(m_sService,SERVICE_CONTROL_STOP,&Service_Status); if(i==0) { printf("stop fail\n"); } return 0; } 驱动: #ifdef __cplusplus extern "C" { #endif #include "wdm.h" #ifdef __cplusplus } #endif ///////////////////////////////////////////////////////////////////////////// // DebugPrint and Guid headers #include "debugprint.h" #define DGL_DEVICE_NAME L"\\Device\\My11c" #define DOS_DEVICE_NAME L"\\DosDevices\\MyFunc11c" typedef struct _MyFUNC_DEVICE_EXTENSION { PDEVICE_OBJECT fdo; PDEVICE_OBJECT NextStackDevice; UNICODE_STRING ifSymLinkName; } MyFUNC_DEVICE_EXTENSION, *PMyFUNC_DEVICE_EXTENSION; NTSTATUS CompleteIrp( PIRP Irp, NTSTATUS status, ULONG info) { Irp->IoStatus.Status = status; Irp->IoStatus.Information = info; IoCompleteRequest(Irp,IO_NO_INCREMENT); return status; } NTSTATUS MyFuncCreate( IN PDEVICE_OBJECT fdo, IN PIRP Irp) { PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp); // DebugPrint( "Create File is %T", &(IrpStack->FileObject->FileName)); return CompleteIrp(Irp,STATUS_SUCCESS,0); } NTSTATUS MyFuncClose( IN PDEVICE_OBJECT fdo, IN PIRP Irp) { // DebugPrintMsg("MyFuncClose"); return CompleteIrp(Irp,STATUS_SUCCESS,0); } #pragma code_seg("PAGE") // start PAGE section VOID MyFuncUnload(IN PDRIVER_OBJECT DriverObject) { DebugPrintMsg("MyFuncUnload"); UNICODE_STRING DOSDeviceName; RtlInitUnicodeString(&DOSDeviceName, DOS_DEVICE_NAME); IoDeleteSymbolicLink(&DOSDeviceName); IoDeleteDevice(DriverObject->DeviceObject); // DebugPrintClose(); } ////////////////////////////////////////////////////////////////////////////// #pragma code_seg() // end PAGE section #pragma code_seg("INIT") // start INIT section extern "C" NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { #if DBG DebugPrintInit("FtFunc checked"); #else DebugPrintInit("FtFunc free"); #endif DebugPrintMsg("DriverEntry begin"); NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT fdo; UNICODE_STRING NtDeviceName; UNICODE_STRING Win32DeviceName; RtlInitUnicodeString(&NtDeviceName,DGL_DEVICE_NAME); RtlInitUnicodeString(&Win32DeviceName,DOS_DEVICE_NAME); // Create our Functional Device Object in fdo status = IoCreateDevice (DriverObject, sizeof(MyFUNC_DEVICE_EXTENSION), &NtDeviceName, // Name FILE_DEVICE_UNKNOWN, 0, FALSE, // Not exclusive &fdo); if( !NT_SUCCESS(status)) return status; // Create device name status = IoCreateSymbolicLink(&Win32DeviceName,&NtDeviceName ); if( !NT_SUCCESS(status)) return status; DriverObject->DriverUnload = MyFuncUnload; DriverObject->MajorFunction[IRP_MJ_CREATE] = MyFuncCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE] = MyFuncClose; DebugPrintMsg("DriverEntry completed"); return status; } #pragma code_seg() // end INIT section  | 
	|
| 
			 7楼# 
								发布于:2005-01-11 16:28				
			
					我作了简单的修改,试了一下好像没什么问题的。
 
							附件是我生成的sys。  | 
	|
					
 
  | 
	
| 
			 8楼# 
								发布于:2005-01-11 16:36				
			
					修改的源码也一起给你把,结果我直接输出到DbgView的。
 
							 | 
	|
					
 
  | 
	
| 
			 9楼# 
								发布于:2005-01-11 17:54				
			修改的源码也一起给你把,结果我直接输出到DbgView的。 用了你的驱动 果然没有错误了!! 但是 如果我编译你的那个驱动文件 就又不能unload了 可能是我的source错了 是不是设置的不对? 我的是 TARGETNAME=Wdm11a TARGETTYPE=DRIVER DRIVERTYPE=WDM TARGETPATH=OBJ INCLUDES=$(BASEDIR)\inc; SOURCES= Sys_Driver.c\ NTTARGETFILES=PostBuildSteps 非常感谢!!  | 
	|
| 
			 10楼# 
								发布于:2005-01-12 10:11				
			
					我编译没有用source文件,source文件我不是很熟悉。
 
							哪位帮着看看吧。  | 
	|
					
						
  | 
	
| 
			 11楼# 
								发布于:2005-01-12 10:27				
			我编译没有用source文件,source文件我不是很熟悉。 这种办法我不会啊 你怎么编译的  | 
	|
| 
			 12楼# 
								发布于:2005-01-12 11:48				
			
					把DRIVERTYPE=WDM
 
							去掉  | 
	|
					
						
  | 
	
| 
			 13楼# 
								发布于:2005-01-12 12:30				
			把DRIVERTYPE=WDM ^_^ 解决 开心 多谢  | 
	|