Ports
May 19, 2013, 03:21:24 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Pages: [1]
  Print  
Author Topic: dllImport in C++  (Read 1907 times)
UmuSBmad
Member
*
Posts: 3


« on: September 28, 2011, 06: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
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1625


WWW
« Reply #1 on: September 28, 2011, 09:01:28 pm »

#include <windows.h>

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

GUID   HidGuid;
HidD_GetHidGuid(&HidGuid);   

Jan
Logged
UmuSBmad
Member
*
Posts: 3


« Reply #2 on: September 29, 2011, 07: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:
#include <windows.h>

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

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

So I'm a bit stumped.
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1625


WWW
« Reply #3 on: September 29, 2011, 09: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
Logged
UmuSBmad
Member
*
Posts: 3


« Reply #4 on: September 29, 2011, 04: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.
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1625


WWW
« Reply #5 on: September 29, 2011, 09: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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!