Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi. In C# you have Dllimport and extern going together to import a specific function from a specific DLL. I want to know how to implement their functionalities in C++ if it's possible. Thanks in advance.
 
E.g. in C#:
[DllImport("setupapi.dll" , CharSet = CharSet::Seeifdef, EntryPoint="SetupDiGetClassDevs")]
extern "C" HDEVINFO SetupDiGetClassDevsUM(
LPGUID ClassGuid,
PCTSTR Enumerator,
HWND hwndParent,
DWORD Flags);
 
To C++:?
Posted 6-Feb-13 22:12pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is a little different in C++.
extern "C"
{
__declspec( dllimport ) HDEVINFO SetupDiGetClassDevsUM( LPGUID ClassGuid, PCTSTR Enumerator, HWND hwndParent, DWORD Flags );
}
but not that different.
I don't know about C# but in C++ you'll also need to link to the DLL that exports this function, by adding its import library to the linker input list in Visual Studio or some thing like #pragma comment(lib,"SetupAPI.lib")
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Most Windows libraries already provide standard C interfaces which are defined in their associated header files. Just check the MSDN documentation[^] for the API call you are interested in, and it will give you the details of the call, parameters, .h and .lib files needed to make use of it.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100