PORTS Forum

Ports and Interfaces => USB => Topic started by: UmuSBmad on September 28, 2011, 07:54:00 pm

Title: dllImport in C++
Post by: UmuSBmad on September 28, 2011, 07:54:00 pm
Hi, in C# the functions to interface with the USB devices come from Dll import statements, I'd like to know how how I can get the same functions in C++ where DllImport doesn't seem to work?
I've tried to understand the C++ code example on http://www.lvr.com/hidpage.htm but I couldn't get it to work and I'm not experienced enough to dissect it. Just a simple example of HidD_GetHidGuid would be great.
Thanks
Title: Re: dllImport in C++
Post by: Jan Axelson on September 28, 2011, 10:01:28 pm
#include <windows.h>

extern "C"
{
  #include <hidsdi.h>
}

GUID   HidGuid;
HidD_GetHidGuid(&HidGuid);   

Jan
Title: Re: dllImport in C++
Post by: UmuSBmad on September 29, 2011, 08:09:48 am
Unfortunately I've still got the same problem. I've downloaded the WDK, installed it to the C: directory and linked the libraries into a fresh C++ project and added "C:\WinDDK\7600.16385.1\inc\api;" (which holds hidsdi.h) to the 'C/C++ additonal includes' in the project properties.
Theres no red lines but when I compile I get a long list of errors, the first ones being:

1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(543): error C2065: '_In_opt_z_' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(543): error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(543): warning C4229: anachronism used : modifiers on data are ignored
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(543): error C2182: '_invalid_parameter' : illegal use of type 'void'
...

This being all my code:
Code: [Select]
#include <windows.h>

extern "C"
{
#include <hidsdi.h>
}

int main()
{
GUID HidGuid;
HidD_GetHidGuid(&HidGuid);
return 0;
}

So I'm a bit stumped.
Title: Re: dllImport in C++
Post by: Jan Axelson on September 29, 2011, 10:30:52 am
See this:

http://stackoverflow.com/questions/1356653/multiple-compiling-errors-with-basic-c-application-on-vs2010-beta-1

or search on the error messages for more help.

Jan
Title: Re: dllImport in C++
Post by: UmuSBmad on September 29, 2011, 05:12:14 pm
Aha thanks for the pointer. There was also a problem with iostream and missing functions (cout) for the same reason as theres an iostream file in the WinDDK directories so got that sorted too.
I just put 'C:\Program Files\Microsoft Visual Studio 10.0\VC\include' above the WinDDK include's in the additional includes property which cleared up the stream of errors. Also had to add hid.lib to the property Linker-Input-Additional Dependencies and then it all worked.
Cheers, you are indeed worthy of your Hero Member status.
Title: Re: dllImport in C++
Post by: Jan Axelson on September 29, 2011, 10:26:27 pm
I'm glad to hear you got it working. Thanks for reporting your solution. I wrote that application quite some time ago!

Jan