__declspec(dllimport)如何加载库 [英] __declspec(dllimport) how to load library

查看:172
本文介绍了__declspec(dllimport)如何加载库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft.com/en-us/library/9h658af8.aspx

MSDN说我可以使用 __ declspec(dllexport)从库导出功能,但是如何加载我的可执行文件库?

MSDN says I can export function from the library with __declspec(dllexport) but how can I load this library in my executable?

我在DLL中有一个导出的函数:

I've got an exported function in DLL:

 __declspec(dllexport) void myfunc(){}

现在我想使用在我的可执行文件中:

And now I would like to use it in my executable:

 __declspec(dllimport) void myfunc(void);

但是我的程序将如何知道在哪里找到这个功能?

But how my program will know where to find this function?

推荐答案

这是编译器/链接器作业,只要你

This is the compiler/linker job, it's done automatically as long as you


  1. 在链接器选项中包含.lib $ /
  2. 在运行时提供DLL,以便它被exe

当您编译DLL时,会生成.lib文件,如果不是您的代码,则会附带该文件。在这种情况下,代码使用 __ declspec(dllexport)进行编译。

The .lib file is generated when you compile the DLL, or is shipped with it if it's not your code. In this case the code is compiled with __declspec(dllexport).

编译您的exe时,编译器会看到包含的函数在DLL中找到。在这种情况下,代码使用 __ declspec(dllimpport)编译。

When compiling your exe, the compiler sees that the included function is to be found in DLL. In this case the code is compiled with __declspec(dllimpport).

链接器随附.lib文件,并在exe中生成适当的说明。

The linker is provided with the .lib file, and generates appropriate instructions in the exe.

这些说明将使Exe找到DLL并在运行时加载导出的函数。 DLL只需要在Exe旁边(还有其他可能的地方)。

These instructions will make the Exe find the DLL and load the exported function at runtime. The DLL just has to be next to the Exe (there are other possible places, however).

__ declspec(dllimpport) __ declspec(dllexport)由宏完成,由...提供Visual C ++当创建一个DLL项目时

这篇关于__declspec(dllimport)如何加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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