最近学习到了应用程序和驱动程序的通讯部分,以下代码是否是一般实现控制驱动程序的模板,但我编译运行时总提示“注册驱动程序失败!”,哪位给看看?谢谢!
.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib kernel32.lib
includelib user32.lib
includelib advapi32.lib
.const
szSYS db 'xxx.sys',0
szSERVICE db 'xxxx',0
szDISPLAY db 'xxxxxx',0
szERRORREG db '注册驱动程序失败!',0
szERRORCON db '无法连接服务控制管理器!',0
.code
start proc
local hSCManager:HANDLE
local hService:HANDLE
local acDriverPath[MAX_PATH]:CHAR
; Open a handle to the SC Manager database 打开服务管理数据库句柄
invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE
;The OpenSCManager function establishes a connection to ;the service control manager on the specified computer and opens the specified database.
.if eax != NULL
mov hSCManager, eax
push eax
invoke GetFullPathName, addr szSYS, sizeof acDriverPath, addr acDriverPath, esp ;获得指定文件的完整路径和文件名
pop eax
; Register driver in SCM active database 注册驱动在服务控制管理数据库
; creates a service object and adds it to the specified service control manager database.
invoke CreateService, hSCManager, addr szSERVICE, addr szDISPLAY, \
SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, \
SERVICE_ERROR_IGNORE, addr acDriverPath, NULL, NULL, NULL, NULL, NULL
.if eax != NULL
mov hService, eax
invoke StartService, hService, 0, NULL ;开启服务
invoke DeleteService, hService
invoke CloseServiceHandle, hService
.else
invoke MessageBox, NULL, addr szERRORREG, NULL, MB_ICONSTOP
.endif
invoke CloseServiceHandle, hSCManager
.else
invoke MessageBox, NULL, addr szERRORCON, NULL, MB_ICONSTOP
.endif