Home » C++ ProgrammingRSS

error LNK2028: unresolved token (0A000299) "extern "C"...

Hi,

Im trying to build a basic sensor, and needs to communicate via USB. I'm using VS C++ 2005, and the code below compiles fine, but gives an error in linking. The functions are from setupapi.lib, and I have added that to the linker (maybe not, now im not even sure) and used #pragma comment to link too, but it still gives me the error, 

 

Please help.

1>Linking...
1>HIDHandler.obj : error LNK2028: unresolved token (0A000299) "extern "C" int __stdcall SetupDiGetDeviceInterfaceDetailW(void *,struct _SP_DEVICE_INTERFACE_DATA *,struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W *,unsigned long,unsigned long *,struct _SP_DEVINFO_DATA *)" (?SetupDiGetDeviceInterfaceDetailW@@$$J224YGHPAXPAU_SP_DEVICE_INTERFACE_DATA@@PAU_SP_DEVICE_INTERFACE_DETAIL_DATA_W@@KPAKPAU_SP_DEVINFO_DATA@@@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2028: unresolved token (0A00029A) "extern "C" int __stdcall SetupDiDestroyDeviceInfoList(void *)" (?SetupDiDestroyDeviceInfoList@@$$J14YGHPAX@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2028: unresolved token (0A00029B) "extern "C" int __stdcall SetupDiEnumDeviceInterfaces(void *,struct _SP_DEVINFO_DATA *,struct _GUID const *,unsigned long,struct _SP_DEVICE_INTERFACE_DATA *)" (?SetupDiEnumDeviceInterfaces@@$$J220YGHPAXPAU_SP_DEVINFO_DATA@@PBU_GUID@@KPAU_SP_DEVICE_INTERFACE_DATA@@@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2028: unresolved token (0A00029C) "extern "C" void * __stdcall SetupDiGetClassDevsW(struct _GUID const *,wchar_t const *,struct HWND__ *,unsigned long)" (?SetupDiGetClassDevsW@@$$J216YGPAXPBU_GUID@@PB_WPAUHWND__@@K@Z) referenced in function "public: int __clrcall HIDHandler::findHIDDev(unsigned int,unsigned int)" (?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z)
1>HIDHandler.obj : error LNK2028: unresolved token (0A000302) "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>HIDHandler.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall MessageBoxW(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBoxW@@$$J216YGHPAUHWND__@@PB_W1I@Z) referenced in function "extern "C" int __cdecl MessageBox(struct HWND__ *,wchar_t const *,wchar_t const *,unsigned int)" (?MessageBox@@$$J0YAHPAUHWND__@@PB_W1I@Z)
1>HIDHandler.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall SetupDiGetDeviceInterfaceDetailW(void *,struct _SP_DEVICE_INTERFACE_DATA *,struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W *,unsigned long,unsigned long *,struct _SP_DEVINFO_DATA *)" (?SetupDiGetDeviceInterfaceDetailW@@$$J224YGHPAXPAU_SP_DEVICE_INTERFACE_DATA@@PAU_SP_DEVICE_INTERFACE_DETAIL_DATA_W@@KPAKPAU_SP_DEVINFO_DATA@@@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall SetupDiDestroyDeviceInfoList(void *)" (?SetupDiDestroyDeviceInfoList@@$$J14YGHPAX@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall SetupDiEnumDeviceInterfaces(void *,struct _SP_DEVINFO_DATA *,struct _GUID const *,unsigned long,struct _SP_DEVICE_INTERFACE_DATA *)" (?SetupDiEnumDeviceInterfaces@@$$J220YGHPAXPAU_SP_DEVINFO_DATA@@PBU_GUID@@KPAU_SP_DEVICE_INTERFACE_DATA@@@Z) referenced in function __catch$?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z$0
1>HIDHandler.obj : error LNK2019: unresolved external symbol "extern "C" void * __stdcall SetupDiGetClassDevsW(struct _GUID const *,wchar_t const *,struct HWND__ *,unsigned long)" (?SetupDiGetClassDevsW@@$$J216YGPAXPBU_GUID@@PB_WPAUHWND__@@K@Z) referenced in function "public: int __clrcall HIDHandler::findHIDDev(unsigned int,unsigned int)" (?findHIDDev@HIDHandler@@$$FQ$AAMHII@Z)
1>C:\Users\Xcorat\Projects\Visual Studio 2005\Projects\teensy1\Debug\dos.exe : fatal error LNK1120: 10 unresolved externals

here's a part of the code,

#include "StdAfx.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <String>
#include <setupapi.h>
#include "hidclass.h"

#include "HIDHandler.h"

#pragma comment (lib, "Setupapi.lib")

HIDHandler::HIDHandler(void)
{
	HINSTANCE hHID = NULL;
	PHidD_GetProductString HidD_GetProductString = NULL;
	PHidD_GetHidGuid HidD_GetHidGuid = NULL;
	PHidD_GetAttributes HidD_GetAttributes = NULL;
	PHidD_SetFeature HidD_SetFeature = NULL;
	PHidD_GetFeature HidD_GetFeature = NULL;

	hHID = LoadLibrary(L"HID.DLL");
	if(!hHID){ //Could not load AtUsbHid.dll, error
		MessageBox(NULL,
			L"Could not load the HID function library",
			L"Error", MB_OK);
			//MessageBoxButtons::OK,			MessageBoxIcon::Error);
	}
	//Update the pointers:
	HidD_GetProductString = (PHidD_GetProductString)
	GetProcAddress(hHID, "HidD_GetProductString");
	HidD_GetHidGuid = (PHidD_GetHidGuid)
	GetProcAddress(hHID, "HidD_GetHidGuid");
	HidD_GetAttributes = (PHidD_GetAttributes)
	GetProcAddress(hHID, "HidD_GetAttributes");
	HidD_SetFeature = (PHidD_SetFeature)
	GetProcAddress(hHID, "HidD_SetFeature");
	HidD_GetFeature = (PHidD_GetFeature)
	GetProcAddress(hHID, "HidD_GetFeature");
}

int HIDHandler::findHIDDev(unsigned VID, unsigned PID){
	GUID HidGuid;
	(HidD_GetHidGuid)(&HidGuid);
	HDEVINFO hDevInfo;
	HANDLE DeviceHandle;
	//Device interace data list
	SP_DEVICE_INTERFACE_DATA devInfoData;
	SP_DEVICE_INTERFACE_DETAIL_DATA detailData;
	char * HIDDevicePath;
	//Get information about HIDstry {
		hDevInfo = SetupDiGetClassDevs
		(&HidGuid,NULL,NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
		if (hDevInfo == INVALID_HANDLE_VALUE)
		return 0;
	} catch (...) {
		return 0;
	}
	//Identify each HID interface
	devInfoData.cbSize = sizeof(devInfoData);
	DWORD MemberIndex = 0;
	bool Result;
	while (1)
	{
		try {
			Result = SetupDiEnumDeviceInterfaces
				(hDevInfo,0,&HidGuid,MemberIndex,&devInfoData);
			if (!Result){
				SetupDiDestroyDeviceInfoList(hDevInfo);
				return (0); //No more devices found
			}
			MemberIndex++;
		} catch (...) {
		return 0;
		}
		//Get the Pathname of the current device//detailData.cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
		detailData.cbSize = 5;
		DWORD Reguired = 0;
		//seems you need to call this func twice,// TODO: if an error occurs, call the function twicetry {
			Result = SetupDiGetDeviceInterfaceDetail
			(hDevInfo,&devInfoData,&detailData,256,&Reguired,NULL);
			if (!Result)
				continue;
		} catch (...) {
			continue;
		}
		//Get Handle for the current devicetry {
			DeviceHandle = CreateFile (detailData.DevicePath,
				GENERIC_READ|GENERIC_WRITE,
				FILE_SHARE_READ|FILE_SHARE_WRITE,
				(LPSECURITY_ATTRIBUTES)NULL,
				OPEN_EXISTING,
				0,
				NULL);
			if (DeviceHandle == INVALID_HANDLE_VALUE) {
				CloseHandle(DeviceHandle);
				continue;
			}
		} catch (...) {
			continue;
		}
		//Read Attributes from the current device
		HIDD_ATTRIBUTES Attributes;
		Attributes.Size = sizeof(Attributes);
		try {
			Result = HidD_GetAttributes (DeviceHandle,&Attributes);
			if (!Result){
				CloseHandle(DeviceHandle);
				continue;
			}
		} catch (...) {
			continue;
		}
		// All information obtained// Attributes.VendorID// Attributes.ProductID// detailData.DevicePath <- Remember for future use// easy example can be:if ((Attributes.VendorID == VID) &&
		(Attributes.ProductID == PID))
		MessageBox(NULL,
			L"Found the device",
			L"Error", MB_OK);
		//strcpy(HIDDevicePath, detailData.DevicePath));
	} //end of while
}


 

4 Answers Found

 

Answer 1

xcorat wrote:

1>HIDHandler.obj : error  LNK2028: unresolved  token (0A000299) "extern  "C" int __stdcall SetupDiGetDeviceInterfaceDetailW(void
*,struct _SP_DEVICE_INTERFACE_DATA *,struct  _SP_DEVICE_INTERFACE_DETAIL_DATA_W *,unsigned long,unsigned long  *,struct
_SP_DEVINFO_DATA *)"

As the documentation for SetupDiGetDeviceInterfaceDetail states, link to  Setupapi.lib


Igor Tandetnik

 

Answer 2

>I have added that to the linker ...
>and used #pragma comment to link too,
>but it still gives me the error,
>#pragma comment (lib, "Setupapi.lib")

You have told it *which* lib file to use,
but have you told the linker *where* to
find that file?

Add the path to the lib file under:
Project/Properties/Linker/General:
"Additional Library Directories"

- Wayne

 

Answer 3

You have told it *which* lib file to use,
but have you told the linker *where* to
find that file?

Add the path to the lib file under:
Project/Properties/Linker/General:
"Additional Library Directories"

- Wayne

ok that part is working. Ok, i had the lib file on my home project folder, and then added it to the place u tald too..! but didnt work, so I added the path to the libraries in tools->options, and added the .lib files on linker->additional dependancies *when it was selected as ALL CONFIGURATION*

now that works, but gives me an error  on linking to hid.lib, i have added that to the same places i added the setupapi.lib..! but still gives me an error, here's a part of the build  log..!! im really in need of help..! thx

 

Linking...
Starting pass 1
Processed /DEFAULTLIB:MSVCRTD
Processed /DEFAULTLIB:OLDNAMES
Processed /DEFAULTLIB:msvcprtd
Processed /DEFAULTLIB:uuid.lib
Processed /DEFAULTLIB:hid.lib
Processed /DEFAULTLIB:setupapi.lib
Searching libraries
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\setupapi.lib:
   Found __imp__SetupDiGetClassDevsW@16
    Referenced in test1.obj
    Loaded setupapi.lib(SETUPAPI.dll)
   Found __IMPORT_DESCRIPTOR_SETUPAPI
    Referenced in setupapi.lib(SETUPAPI.dll)
    Loaded setupapi.lib(SETUPAPI.dll)
   Found __NULL_IMPORT_DESCRIPTOR
    Referenced in setupapi.lib(SETUPAPI.dll)
    Loaded setupapi.lib(SETUPAPI.dll)
   Found SETUPAPI_NULL_THUNK_DATA
    Referenced in setupapi.lib(SETUPAPI.dll)
    Loaded setupapi.lib(SETUPAPI.dll)
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\hid.lib:
.....
....
....  

    Loaded msvcprtd.lib(MSVCP80D.dll)
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\setupapi.lib:
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\hid.lib:
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\kernel32.lib:
   Found __imp__InterlockedExchange@8
    Referenced in MSVCRTD.lib(crtexe.obj)
    Loaded kernel32.lib(KERNEL32.dll)
  ...
...
..

  Searching C:\Program Files (x86)\Microsoft Visual Studio 8\VC\lib\msvcprtd.lib:
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\setupapi.lib:
  Searching C:\WinDDK\7600.16385.1\lib\win7\i386\hid.lib:
Finished searching libraries
Finished pass 1
Generating non-SAFESEH image.
Invoking CVTRES.EXE:
 /machine:x86
 /verbose
 /out:"C:\Users\Xcorat\AppData\Local\Temp\lnkCD1F.tmp"
 /readonly
 ".\Debug\test1.exe.embed.manifest.res"
Microsoft (R) Windows Resource To Object Converter Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
adding resource. type:MANIFEST, name:1, language:0x0409, flags:0x30, size:406
test1.obj : error LNK2019: unresolved  external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z) referenced in function _main
C:\Users\Xcorat\Projects\Visual Studio 2005\Projects\testhid\Debug\test1.exe : fatal error LNK1120: 1 unresolved externals

 

Answer 4

xcorat wrote:
>
>ok that part is working. Ok, i had the lib file on my home project
>folder, and then added it to the place u tald too..! but didnt work, so I added the path to the libraries in tools->options, and added the .lib files on linker->additional dependancies *when it was selected as ALL CONFIGURATION*
>
>now that works, but gives me an error  on linking to hid.lib, i have
>added that to the same places i added the setupapi.lib..! but still
>gives me an error, here's a part of the build  log..!! im really in
>need of help..! thx
>...
>Microsoft (R) Windows Resource To Object Converter Version 8.00.50727.762
>Copyright (C) Microsoft Corporation. All rights reserved.
>adding resource. type:MANIFEST, name:1, language:0x0409, flags:0x30, size:406
>test1.obj : error LNK2019: unresolved  external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z) referenced in function _main
 
This should be clear. The name that you are referring to has C++
decorations (the "(?HidD...@@@Z)" part), but it needs to be C decorated.
So, surround the call to "hidsdi.h" like this:
 
extern "C" {
#include "hidsdi.h"
}
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
 
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter