Dllimport,外部功能 [英] Dllimport, extern functionality

查看:77
本文介绍了Dllimport,外部功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。在C#中,你有Dllimport和extern一起从特定的DLL导入一个特定的函数。我想知道如果可能的话,如何用C ++实现它们的功能。提前致谢。



例如在C#:

[的DllImport( setupapi.dll,字符集=字符集:: Seeifdef,入口点= SetupDiGetClassDevs)]

的extern C HDEVINFO SetupDiGetClassDevsUM(

LPGUID ClassGuid,

PCTSTR枚举器,

HWND hwndParent,

DWORD标志);



到C ++:?

解决方案
它是在C ++有点不同。

'pre>外部的 C
{
__declspec(dllimport的)HDEVINFO SetupDiGetClassDevsUM(LPGUID ClassGuid,PCTSTR枚举,HWND hwndParent,DWORD标志);
}



但没有那么不同。

我不知道C#但是在C ++中你还需要链接到导出此函数的DLL,方法是将其导入库添加到Visual Studio中的链接器输入列表或类似 #pragma comment(lib,SetupAPI.lib)


大多数Windows库已经提供了标准的C接口,这些接口在相关的头文件中定义。只需查看 MSDN文档 [ ^ ]您感兴趣的API调用,它将为您提供调用的详细信息,参数, .h .lib 需要使用它的文件。


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++:?

解决方案

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")


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.


这篇关于Dllimport,外部功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆