Dll Wrapper

 


1. NI对dll wrapper的介绍:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PA8QSAW

Issue Details

What is a wrapper DLL, and when do I need one?

I need to call an external DLL in LabVIEW, but the parameters of the function do not easily map to LabVIEW data types.

Solution

A wrapper is a piece of software that provides a compatibility layer to another piece of software. One is often necessary when developing LabVIEW applications because third-party DLLs are typically designed to be accessed from C (or similar low-level languages) and not LabVIEW. Such a DLL may, for example, return pointers or complex data structures which LabVIEW cannot easily handle. 

Writing a wrapper DLL can be compared to writing a completely separate program in C that accesses the original DLL in the way the original author intended. In turn, this wrapper program has been specifically designed to be accessed from LabVIEW. In this sense, the new C program "wraps" around the original C program (DLL) and provides a layer of compatibility. The benefit of a wrapper is that the source code for the original DLL is not necessary, as it does not need to be modified in any way.

 

2

This article proposes a new type of wrapper requiring only minimal code changes to switch between dynamic and static loading but still offering all the features of existing DLL-wrappers and more.:

https://www.codeproject.com/articles/224869/yet-another-dll-wrapper-for-dynamic-loading

 

3  A Tool


http://www.dllwrapper.com/dllwrapper_download.htm

 

4 github: DLL Wrapper Generator  -- by Python

https://github.com/SeanPesce/DLL_Wrapper_Generator

https://github.com/mavenlin/Dll_Wrapper_Gen
 

 

5 github: DLL intercept(拦截)

 

https://github.com/kevinalmansa/DLL_Wrapper

 

在Qt控制台应用程序中调用DLL,你可以按照以下步骤进行操作: 1. 将DLL文件放置在Qt项目的文件夹中,或者指定其绝对路径。 2. 在Qt项目中创建一个头文件(例如,dllwrapper.h),用于声明要调用的DLL函数的函数指针和相关数据结构。 3. 在dllwrapper.h文件中,使用`#include`指令包含DLL的头文件。如果DLL没有提供头文件,则需要自己编写函数的声明。 4. 在dllwrapper.h文件中,声明函数指针来存储DLL函数的地址。例如,如果要调用名为`MyFunction`的函数,则可以使用以下代码声明函数指针: ```cpp typedef int (*MyFunctionType)(int); ``` 5. 在dllwrapper.h文件中,创建一个类或命名空间来管理DLL函数的加载和调用。在类或命名空间中,添加一个静态成员函数用于加载DLL并获取函数地址。例如: ```cpp class DLLWrapper { public: static bool loadDLL(); static MyFunctionType myFunction; }; ``` 6. 在dllwrapper.cpp文件中实现`loadDLL`和其他函数。`loadDLL`函数中,使用`QLibrary`类来加载DLL并获取函数地址。例如: ```cpp bool DLLWrapper::loadDLL() { QLibrary dll("your_dll_name.dll"); if (dll.load()) { myFunction = (MyFunctionType)dll.resolve("MyFunction"); if (myFunction) { return true; } } return false; } ``` 7. 在主函数或其他需要调用DLL函数的地方,调用`loadDLL`函数来加载DLL。例如: ```cpp if (DLLWrapper::loadDLL()) { int result = DLLWrapper::myFunction(42); // 处理DLL函数的返回值 } else { // 处理加载DLL失败的情况 } ``` 这样,你就可以在Qt控制台应用程序中成功调用DLL函数了。请注意,上述示例代码仅作为演示,你需要根据实际情况进行修改和适配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

First Snowflakes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值