New or updated MSVC detected. Updating DDK environment....
Setting environment for using Microsoft Visual C++ tools.
Starting dirs creation...Completed.
C:\NTDDK>cd\
C:\>cd HelloWorld
C:\HelloWorld>build
BUILD: Object root set to: ==> objfre
BUILD: /i switch ignored
BUILD: Compile and Link for i386
BUILD: Loading c:\NTDDK\build.dat...
BUILD: Computing Include file dependencies:
BUILD: Examining c:\helloworld directory for files to compile.
c:\helloworld - 1 source files (127 lines)
BUILD: Saving c:\NTDDK\build.dat...
BUILD: Compiling c:\helloworld directory
Compiling - helloworld.c for i386
BUILD: Linking c:\helloworld directory
Linking Executable - i386\helloworld.sys for i386
BUILD: Done
1 file compiled
1 executable built
C:\HelloWorld>
现在C:\HelloWorld\i386目录下,就有了HelloWorld.sys。
=======================================================================================
=============
驱动程序的安装如同安装服务一样,唯一不同的是,创建服务时,类型是内核驱动,其他跟操作服务没什
么区别。
安装驱动程序流程:
1,调用OpenSCManager()打开服务控制管理器
2,调用CreateService()创建一个服务,服务类型为内核驱动
3,调用OpenService()取得服务句柄
启动服务
4,调用StartService()启动服务
停止服务
4,调用ControlService()停止服务
删除服务
4,调用DeleteService()删除服务
5,调用CloseServiceHandle()关闭服务句柄
操作驱动程序流程:
1,调用CreateFile()取得设备句柄
2,调用DeviceIoControl()传递I/O控制代码
3,调用CloseHandle()关闭设备句柄
这里有一个完整的驱动安装程序,所以我就不写了,只给出操作驱动程序的代码
完整代码:
#define DEBUGMSG
#include
#include
#include
#define DEVICE_HELLO_INDEX 0x860
#define START_HELLPWORLD
CTL_CODE(FILE_DEVICE_UNKNOWN,DEVICE_HELLO_INDEX,METHOD_BUFFERED,FILE_ANY_ACCESS)
#define STOP_HELLPWORLD
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-47708-4.html
台湾问题已经超出了政治范畴
不然有点小卡