现成代码编译不过,为什么?

hamsun2008   2007-9-6 17:05 楼主
代码是《Windows WDM设备驱动程序开发指南》随书代码,编译后出现Link错误。

为什么?

回复评论 (10)

现象为
Deleting intermediate files and output files for project 'HidKbdUser - Win32 Debug'.
--------------------Configuration: HidKbdUser - Win32 Debug--------------------
Compiling resources...
Compiling...
HidKbdUser.cpp
Linking...
HidKbdUser.obj : error LNK2001: unresolved external symbol "unsigned char __stdcall HidD_FreePreparsedData(struct _HIDP_PREPARSED_DATA *)" (?HidD_FreePreparsedData@@YGEPAU_HIDP_PREPARSED_DATA@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "long __stdcall HidP_GetSpecificButtonCaps(enum _HIDP_REPORT_TYPE,unsigned short,unsigned short,unsigned short,struct _HIDP_BUTTON_CAPS *,unsigned short *,struct _HIDP_PREPARSED_DATA *)" (?H
idP_GetSpecificButtonCaps@@YGJW4_HIDP_REPORT_TYPE@@GGGPAU_HIDP_BUTTON_CAPS@@PAGPAU_HIDP_PREPARSED_DATA@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "long __stdcall HidP_GetCaps(struct _HIDP_PREPARSED_DATA *,struct _HIDP_CAPS *)" (?HidP_GetCaps@@YGJPAU_HIDP_PREPARSED_DATA@@PAU_HIDP_CAPS@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "unsigned char __stdcall HidD_GetPreparsedData(void *,struct _HIDP_PREPARSED_DATA * *)" (?HidD_GetPreparsedData@@YGEPAXPAPAU_HIDP_PREPARSED_DATA@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "unsigned char __stdcall HidD_GetAttributes(void *,struct _HIDD_ATTRIBUTES *)" (?HidD_GetAttributes@@YGEPAXPAU_HIDD_ATTRIBUTES@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "long __stdcall HidP_UsageListDifference(unsigned short *,unsigned short *,unsigned short *,unsigned short *,unsigned long)" (?HidP_UsageListDifference@@YGJPAG000K@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "long __stdcall HidP_GetUsagesEx(enum _HIDP_REPORT_TYPE,unsigned short,struct _USAGE_AND_PAGE *,unsigned long *,struct _HIDP_PREPARSED_DATA *,char *,unsigned long)" (?HidP_GetUsagesEx@@YGJW4
_HIDP_REPORT_TYPE@@GPAU_USAGE_AND_PAGE@@PAKPAU_HIDP_PREPARSED_DATA@@PADK@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "unsigned long __stdcall HidP_MaxUsageListLength(enum _HIDP_REPORT_TYPE,unsigned short,struct _HIDP_PREPARSED_DATA *)" (?HidP_MaxUsageListLength@@YGKW4_HIDP_REPORT_TYPE@@GPAU_HIDP_PREPARSED_
DATA@@@Z)
HidKbdUser.obj : error LNK2001: unresolved external symbol "long __stdcall HidP_SetUsages(enum _HIDP_REPORT_TYPE,unsigned short,unsigned short,unsigned short *,unsigned long *,struct _HIDP_PREPARSED_DATA *,char *,unsigned long)" (?HidP_SetUsages@@YG
JW4_HIDP_REPORT_TYPE@@GGPAGPAKPAU_HIDP_PREPARSED_DATA@@PADK@Z)
Debug/HidKbdUser.exe : fatal error LNK1120: 10 unresolved externals
Error executing link.exe.

HidKbdUser.exe - 11 error(s), 0 warning(s)

前提是已安装了DDK,SDK等,且已#include "C:\WINDDK\2600.1106\inc\wxp\setupapi.h"
#include "C:\WINDDK\2600.1106\inc\wxp\hidsdi.h"

求解...
点赞  2007-9-6 17:07
就Chris Cant那本。谁有试过编译器中的实例不?
点赞  2007-9-8 11:22
你安装DDK了没有?有没有配置好DDK?
点赞  2007-9-8 17:16
一般应该不会有这个问题啊。
看看project->setting那边有没有加上setupapi.lib 和hid.lib?没有的话加上
点赞  2007-9-10 00:06
请问DDK怎么配置啊?
setupapi.lib与hid.lib通过如下2句加入的
#pragra comment(lib,"setupapi,lib")
#pragra comment(lib,"hid,lib")

点赞  2007-9-10 12:35
我正找 《Windows WDM设备驱动程序开发指南》随书代码 ,网上一直找不到
麻烦lz给我发一份吧,谢谢了

yangming_liang@163.com
点赞  2007-9-14 14:51
一般环境配置的影响可能性比较大
点赞  2007-9-14 15:41
可以肯定的说你的lib文件没有被VC找到,所以link错误.其实不用#include "C:\WINDDK\2600.1106\inc\wxp\setupapi.h"
#include "C:\WINDDK\2600.1106\inc\wxp\hidsdi.h"
绝对路径使用好像不太明智哦,在VC的include,及Lib里加入C:\WINDDK\2600.1106\inc,及C:\WINDDK\2600.1106\Lib(对应的你可以调节),应该就可以了.
点赞  2007-9-19 17:09
路径路径问题啊、、
点赞  2007-9-25 13:09
我也碰到这个问题

SBPortDlg.obj : error LNK2001: unresolved external symbol "unsigned char __stdcall HidD_GetAttributes(void *,struct _HIDD_ATTRIBUTES *)" (?HidD_GetAttributes@@YGEPAXPAU_HIDD_ATTRIBUTES@@@Z)
USBPortDlg.obj : error LNK2001: unresolved external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z)
Debug/USBPort.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
点赞  2008-5-7 17:15
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复