Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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")
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900