Posted on 2006-01-03 10:11
任我行 閱讀(2313)
評論(4) 編輯 收藏 引用 所屬分類:
驅動開發
作為一個完整的例子,你開發出來驅動還必須要能安裝。所以下面我講一下安裝。
如果前面的編譯過程沒有錯誤的話,現在我們應該已經得到了一個HelloWDM.sys文件,假設它是放在D:\HelloWDM\objfre\i386中。
安裝WDM驅動程序可以用兩種方法,一種是利用注冊表,還有一種是利用INF文件。我們一般是采用INF文件(這是微軟推薦的)。INF文件可以在 WINNT\INF 目錄中找到很多。為了順利安裝,我在這里先給出 HelloWDM 所需要的 HelloWDM.INF 文件:
;; The Win2K DDK documentation contains an excellent INF reference.
;--------- Version Section ---------------------------------------------------
[Version] Signature="$CHICAGO$" Provider=LC_Device DriverVer=8/21/2002,3.0.0.3
; If device fits one of the standard classes, use the name and GUID here, ; otherwise create your own device class and GUID as this example shows.
Class=Unknown ClassGUID={ff646f80-8def-11d2-9449-00105a075f6b}
;--------- SourceDiskNames and SourceDiskFiles Section -----------------------
; These sections identify source disks and files for installation. They are ; shown here as an example, but commented out.
[SourceDisksNames] 1 = "HelloWDM",Disk1,,
[SourceDisksFiles] HelloWDM.sys = 1,objfre\i386,
;--------- ClassInstall/ClassInstall32 Section -------------------------------
; Not necessary if using a standard class
; 9X Style [ClassInstall] Addreg=Class_AddReg
; NT Style [ClassInstall32] Addreg=Class_AddReg
[Class_AddReg] HKR,,,,%DeviceClassName% HKR,,Icon,,"-5"
;--------- DestinationDirs Section -------------------------------------------
[DestinationDirs] YouMark_Files_Driver = 10,System32\Drivers
;--------- Manufacturer and Models Sections ----------------------------------
[Manufacturer] %MfgName%=Mfg0
[Mfg0]
; PCI hardware Ids use the form ; PCI\VEN_aaaa&DEV_bbbb&SUBSYS_cccccccc&REV_dd ;改成你自己的ID %DeviceDesc%=YouMark_DDI, PCI\VEN_9999&DEV_9999
;---------- DDInstall Sections ----------------------------------------------- ; --------- Windows 9X -----------------
; Experimentation has shown that DDInstall root names greater than 19 characters ; cause problems in Windows 98
[YouMark_DDI] CopyFiles=YouMark_Files_Driver AddReg=YouMark_9X_AddReg
[YouMark_9X_AddReg] HKR,,DevLoader,,*ntkern HKR,,NTMPDriver,,HelloWDM.sys HKR, "Parameters", "BreakOnEntry", 0x00010001, 0
; --------- Windows NT -----------------
[YouMark_DDI.NT] CopyFiles=YouMark_Files_Driver AddReg=YouMark_NT_AddReg
[YouMark_DDI.NT.Services] Addservice = HelloWDM, 0x00000002, YouMark_AddService
[YouMark_AddService] DisplayName = %SvcDesc% ServiceType = 1 ; SERVICE_KERNEL_DRIVER StartType = 3 ; SERVICE_DEMAND_START ErrorControl = 1 ; SERVICE_ERROR_NORMAL ServiceBinary = %10%\System32\Drivers\HelloWDM.sys
[YouMark_NT_AddReg] HKLM, "System\CurrentControlSet\Services\HelloWDM\Parameters",\ "BreakOnEntry", 0x00010001, 0
; --------- Files (common) -------------
[YouMark_Files_Driver] HelloWDM.sys
;--------- Strings Section ---------------------------------------------------
[Strings] ProviderName="Flying L Co.,Ltd." MfgName="LC Soft" DeviceDesc="Hello World WDM!" DeviceClassName="LC_Device" SvcDesc="???"
|
注意它可以同時在Win98或者Win2000中使用(系統會通過這個INF文件里面的字段名稱,自動選擇適合當前系統的安裝方法的)。關于INF文件的各個字段含義現在我也不知道,所以也沒有辦法說清楚,如果誰看到這篇文章,而又知道的話,不妨為我一份。
準備好這個 HelloWDM.INF 文件后,讓我們打開控制面板,雙擊“添加/刪除硬件”,選擇“添加/排除設備故障”->“添加新設備”->“否,我想從列表選擇硬件”->“其它設備”->“從磁盤安裝”,選擇 HelloWDM.INF 所在的路徑,然后安裝。
當安裝完成后,系統就會添加上你寫好的驅動程序了。(可以在“設備管理器”中查看到)。然后重啟電腦,這個驅動程序就投入使用啦。
關于安裝,我也只知道這么多,到底安裝驅動程序時,操作系統都作了些什么,我也不是很清楚,等我弄明白了我再貼上。