将C ++ dll包装在另一个C ++ dll中 [英] Wrap C++ dll in Another C++ dll

查看:121
本文介绍了将C ++ dll包装在另一个C ++ dll中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个C ++ dll,想用另一个C ++ dll包装,并调用第一个dll的函数.
我该如何包装?
问候,

Hi,
I have one C++ dll and want wrap that by another C++ dll and call functions of this first dll.
How I can wrap that?
Regards,

推荐答案

调用dll的导出函数没有太大区别,无论您是从exe调用还是从另一个dll调用.

要调用dll的导出函数,您有两个选择:显式或隐式链接.

我认为此MSDN文章 [隐式链接 [ ^ ].您将需要要链接的dll的头文件(h)和导入库文件(lib).

例如,您有一个test.exe,dll1.dll和dll2.dll,它们像这样链接:
test.exe-> dll1.dll-> dll2.dll.我相信test.exe和dll1.dll之间的链接已建立(否则,您不会问).因此,要将dll1与dll2链接起来,您需要dll2中的h和lib文件.例如,您具有dll2_exports.h和dll2.lib.在这种情况下,请在您的dll1的cpp文件中添加以下行:
There is no much difference when you call the exported function of a dll regardless whether you are calling from an exe or from another dll.

To call exported functions of a dll you have two options: explicit or implicit linking.

I think this MSDN Article[^] could be a good starting point for you.

I recommend you start with Implicit Linking[^]. You will need a header (h) file and an import library file (lib) of the dll you would like to link.

For example, you have a test.exe, dll1.dll and dll2.dll, that are linked like this:
test.exe->dll1.dll->dll2.dll. I believe the link between test.exe and dll1.dll is established (otherwise you wouldn''t ask). So, to link dll1 with dll2 you need the h and lib file from dll2. For example you have dll2_exports.h and dll2.lib. In this case within a cpp file of your dll1 add this line:
#include "dll1_exports.h"


然后像平常一样从dll2调用函数.

在dll1的链接选项中,您需要添加对dll2.lib的引用.如果您使用的是Visual Studio,请在解决方案资源管理器中右键单击"dll1"的项目,然后选择属性".导航到Linker-> Input.在其他依赖项"中,键入dll2.lib.

现在建立dll1.现在应该将它与dll2链接起来


Then call the functions from dll2 as you would normally do.

In the link options of dll1 you would need to add a reference to your dll2.lib. Provided you use Visual Studio, Right click on project of "dll1" in the Solution Explorer and select Properties. Navigate to Linker->Input. In the Additional Dependencies type dll2.lib.

Now build dll1. It should now be linked with dll2


这篇关于将C ++ dll包装在另一个C ++ dll中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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