博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
将C++ DLL Wrap后供.NET 调用
阅读量:7143 次
发布时间:2019-06-29

本文共 1572 字,大约阅读时间需要 5 分钟。

What you would do is providing call stubs from your DLL that then are accessible via PInvoke, e.g.

//wrapper.cpp

#include "manufacturer.h"
#pragma comment(lib,"manufacturer.lib")

extern "C" __declspec(dllexport) int WrapperCallManufacturerFunc1(int a, int b)

{
    return ManufacturerFunc1(a,b);
}

extern "C" __declspec(dllexport) char* WrapperCallManufacturerFunc2(char* pString)

{
    return ManufacturerFunc2(pString);
}

extern "C" __declspec(dllexport) double WrapperCallManufacturerFunc3(double d)

{
    return ManufacturerFunc3(d);
}

extern "C" __declspec(dllexport) void WrapperCallManufacturerFunc4()

{
    ManufacturerFunc4();
}

That's basically it. The 'extern "C"' statement is used to tell the compiler to not apply C++ name mangling, i.e. the functions names are not decorated and exported 'as is'. The return types resemble the return types of the functions in the .lib you want to call, except for 'void' functions where your function is 'void' also, yet the 'return' statement is not used. Then you can access the wrapper functions like

Declare Auto Function ManufacturerFunc1  Lib "wrapper.dll" Alias "WrapperCallManufacturerFunc1 " ( _

    ByVal a As Integer, _
    ByVal b As Integer) _
    As Integer

or

Imports System.Runtime.InteropServices

Public Class Win32
    Declare Auto Function WrapperCallManufacturerFunc1 Lib "wrapper.dll" _
       (ByVal a As Integer, _
        ByVal b As Integer) As Integer
End Class

See also  ("Walkthrough: Calling Windows APIs") and  ("Creating Prototypes in Managed Code")

本文转自斯克迪亚博客园博客,原文链接:http://www.cnblogs.com/sgsoft/archive/2009/12/24/1631651.html,如需转载请自行联系原作者

你可能感兴趣的文章
Android的两种菜单
查看>>
poj 1218 THE DRUNK JAILER
查看>>
WordPress SEO ☞ WordPress网站终极优化指南
查看>>
Environment 常用方法
查看>>
【TYVJ】1338 QQ农场(最大流+最大权闭合图)
查看>>
解决Python2.7的UnicodeEncodeError: 'ascii' codec can’t encode异常错误
查看>>
最近在准备开发进销存管理系统
查看>>
TCP/IP协议
查看>>
【C#】Entity Framework 增删改查和事务操作
查看>>
原创:谨以此文怀念曾经的妹妹
查看>>
作为平台的Windows PowerShell(二)
查看>>
Linux find example
查看>>
jquery之超简单的div显示和隐藏特效demo
查看>>
1、开发自定义组件简要
查看>>
使用Ksoap2调用Web Service加入SoapHeader
查看>>
[Linux] 如何禁止使用口令只允许使用密钥建立 SSH 连接
查看>>
悟透JavaScript
查看>>
MySQL批量更新死锁案例分析--转载
查看>>
sql over的作用及用法
查看>>
Android 字体设置
查看>>