简体   繁体   English

C ++和C#,如何在C ++中创建包装器dll,以便C#调用C ++ dll中的实例函数?

[英]C++ & C#, how to create wrapper dll in C++ for C# to call instance function in C++ dll?

Received an unmanaged C++ dll with instance functions which need to be called from my C#. 收到了一个非托管的C ++ dll ,其中包含需要从我的C#调用的实例函数。 need to write a wrapper C++ dll to bridge the C# and original C++ dll as suggested by experts here. 需要编写包装C ++ dll来桥接C#和原始C ++ dll ,如此处专家所建议的那样。 it is new to me and want to learn from you. 这对我来说是新手,想向您学习。

Header file of the original C++ dll likes this: 原始C ++ dll的头文件如下所示:

class EXPORT_MACRO NB_DPSM 
{ 
private: 
    string sFileNameToAnalyze ; 

public: 
    NB_DPSM(void); 
    ~NB_DPSM(void); 

    void setFileNameToAnalyze(string FileNameToAnalyze) ;     
    int WriteGenbenchData(string& message) ; 
}; 

Start from a Class Library project template or CLR Empty Project template? 从类库项目模板还是CLR空项目模板开始?

What's the wrapper code should look like? 包装代码应该是什么样的?

Anywhere has step by step example for this? 哪里有逐步的示例?

thanks, 谢谢,

Oops, didn't read the question quite correctly. 糟糕,阅读的问题不太正确。 Check out this article, http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/ 查看这篇文章, http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/

1) Need list of functions exported by the dll, which should be available in the header file. 1)需要由dll导出的功能列表,该列表应在头文件中可用。 2) Do DllImports for the functions you want to use 3) Marshal in/out parameters appropriately 2)对要使用的功能执行DllImports 3)适当地编组输入/输出参数

This link should explain in more detail, http://msdn.microsoft.com/en-us/library/aa288468(VS.71).aspx 此链接应该更详细地解释, http://msdn.microsoft.com/zh-cn/library/aa288468(VS.71).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM