阅读:2361回复:1
Help关于编写SCSI驱动的问题
我想实现一个很简单的功能,即编程实现安装SCSI和RAID控制器的驱动,SCSI和RAID控制器的驱动所需的文件.sys,.inf,.dll和注册表文件都有。编程的思路即为根据.inf文件将相应的文件和注册表项放到对应的注册表项和路径中去。
在网上找到一个例子: 编程环境如下:VS2008和DDK 代码如下: 假设已有abc.inf和abc.sys文件 #include "stdafx.h" #include <setupapi.h> #pragma comment( lib, "setupapi") #include <newdev.h> #pragma comment( lib, "C:\\NTDDK\\libfre\\i386\\newdev.lib") #include <tchar.h> #include <stdlib.h> int main(int argc, char* argv[]) { printf("Hello World!\n"); CopyAbcNT5Inf(); return 0; } UINT __stdcall CopyAbcNT5Inf(void) { BOOL ret = FALSE; UINT n = 0; TCHAR strWinDir[_MAX_PATH], strInf[_MAX_PATH], strInfDes[_MAX_PATH]; ZeroMemory( strWinDir, _MAX_PATH*sizeof(TCHAR)); ZeroMemory( strInf, _MAX_PATH*sizeof(TCHAR)); ZeroMemory( strInfDes, _MAX_PATH*sizeof(TCHAR)); // Get the Windows Directory path n = GetWindowsDirectory(strWinDir, _MAX_PATH); if( n == 0) return FALSE; // Append the name of the INF file _tcscpy( strInf, strWinDir); _tcscat( strInf, _T( "\\Inf\\NIFB.inf")); // Call SetupCopyOEMInf() to invoke Windows to generate the PNF(procompiled INF file) file abc.PNF ret = SetupCopyOEMInf( strInf, NULL, SPOST_NONE,0, strInfDes, _MAX_PATH, NULL, NULL); if( !ret) return ret; BOOL bRebootRequired = FALSE; BOOLEAN bRet=0; bRet = UpdateDriverForPlugAndPlayDevices( NULL, _T("PCMCIA\\ABC_Technology-PCMCIA-ABC/2-3D57"), strInfDes, INSTALLFLAG_FORCE, &bRebootRequired); bRet = UpdateDriverForPlugAndPlayDevices( NULL, _T("PCI\\VEN_9010&DEV_9008&SUBSYS_00000000&REV_00"), strInfDes, INSTALLFLAG_FORCE, &bRebootRequired); return ret; } 编译错误如下: TestDriver.cpp c:\program files\microsoft sdks\windows\v6.0a\include\setupapi.h(60) : error C2143: 语法错误 : 缺少“;”(在“*”的前面) c:\program files\microsoft sdks\windows\v6.0a\include\setupapi.h(60) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\program files\microsoft sdks\windows\v6.0a\include\setupapi.h(60) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\program files\microsoft sdks\windows\v6.0a\include\spapidef.h(23) : error C2146: 语法错误 : 缺少“;”(在标识符“SP_LOG_TOKEN”的前面) c:\program files\microsoft sdks\windows\v6.0a\include\spapidef.h(23) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\program files\microsoft sdks\windows\v6.0a\include\spapidef.h(23) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\program files\microsoft sdks\windows\v6.0a\include\commctrl.h(19) : error C2059: 语法错误 : “return” c:\program files\microsoft sdks\windows\v6.0a\include\prsht.h(97) : error C2065: “CALLBACK”: 未声明的标识符 c:\program files\microsoft sdks\windows\v6.0a\include\prsht.h(97) : error C2065: “LPFNPSPCALLBACKA”: 未声明的标识符 c:\program files\microsoft sdks\windows\v6.0a\include\prsht.h(97) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int c:\program files\microsoft sdks\windows\v6.0a\include\prsht.h(97) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译 生成日志保存在“file://f:\驱动\Drivers\TestDriver\Debug\BuildLog.htm” TestDriver - 11 个错误,0 个警告 已根据网上的方法将DDK下的inc和lib路径加入,并且置顶。并尝试用VC自己的setupapi.h 均上述错误。请高手指点一二,谢谢! |
|
沙发#
发布于:2009-07-07 18:14
回 楼主(laronze) 的帖子
更正一下:#pragma comment( lib, "C:\\NTDDK\\libfre\\i386\\newdev.lib")改为:#pragma comment( lib, "D:\Program Files\WINDDK\3790.1830\lib\wxp\i386") 补充一下,我的系统是xp的,安装的DDK是支持2k, 2003, xp的。 |
|