Vc6Solution to USB programming Link error in Environment
Background:
Programming Environment: Visual C ++ 6.0 + SP6
Operating System: Windows XP Service Pack 3
Raise questions:
The following error occurs when you reference the classic USB view source code in an MFC application:
USB. OBJ: Error lnk2001: unresolved external symbol "unsigned long _ stdcall cm_get_parent (unsigned long *, unsigned long, unsigned long )"(? Cm_get_parent @ ygkpakkk @ Z)
USB. OBJ: Error lnk2001: unresolved external symbol "unsigned long _ stdcall cm_get_sibling (unsigned long *, unsigned long, unsigned long )"(? Cm_get_sibling @ ygkpakkk @ Z)
USB. OBJ: Error lnk2001: unresolved external symbol "unsigned long _ stdcall cm_get_child (unsigned long *, unsigned long, unsigned long )"(? Cm_get_child @ ygkpakkk @ Z)
USB. OBJ: Error lnk2001: unresolved external symbol "unsigned long _ stdcall equals (unsigned long, unsigned long *, unsigned long *, void *, unsigned long *, unsigned long )"(? Cm_get_devnode_registry_propertya @ ygkkkpakpax0k @
Z)
USB. OBJ: Error lnk2001: unresolved external symbol "unsigned long _ stdcall cm_locate_devnodea (unsigned long *, char *, unsigned long )"(? Cm_locate_devnodea @ ygkpakpadk @ Z)
../Bin/debug/atsync.exe: Fatal error lnk1120: 5 unresolved externals
Analyze the problem:
Cm_locate_devnode
Cm_get_devnode_registry_property
Cm_get_sibling
Cm_get_child
Cm_get_parent
These functions are all from the same cfgmgr32.lib static Link Library,
The cfgmgr32.lib library should be compiled in C language. Therefore, when using C ++ for programming, you cannot simply use include When referencing the cfgmgr32.h header file, that is, # include "cfgmgr32.h ", the extern "C" statement must be added.
Solution:
# Ifdef _ cplusplus
Extern "C "{
# Include "cfgmgr32.h"
}
# Endif