问题描述
我有一个C ++项目。我承认,我是一个在C完全零++。但我仍需要编写一个C ++。Net组件,所以我可以与使用它的非托管C ++库。所以,我有什么:1)非托管项目的头文件。2)非托管项目的库文件(.dll的和.LIB的)3)一个空的C ++。NET项目,我打算作为一个包装使用我的C#应用程序
I've a c++ project. I admit that I'm a complete ZERO in c++. But still I need to write a c++.net wrapper so I could work with an unmanaged c++ library using it. So what I have:1) unmanaged project's header files.2) unmanaged project's libraries (.dll's and .lib's)3) an empty C++.NET project which I plan to use as a wrapper for my c# application
我如何开始?我甚至不知道如何设置一个引用非托管库。
How can I start? I don't even know how to set a reference to an unmanaged library.
S.O.S。
推荐答案
<一个href="http://www.$c$cproject.com/KB/mcpp/quickcppcli.aspx#A8">http://www.$c$cproject.com/KB/mcpp/quickcppcli.aspx#A8
这是大方向。您需要创建C ++ / CLI类库项目,添加.NET类,它(StudentWrapper本示例中),创建非托管类的实例作为管理类的成员,并且包裹每个非托管类的函数。非受管库使用链接的依赖列表添加到C ++ / CLI的项目,而不是作为参考。在项目 - 属性 - 链接器打开附加依赖与添加的.lib名有
This is general direction. You need to create C++/CLI Class Library project, add .NET class to it (StudentWrapper in this sample), create unmanaged class instance as managed class member, and wrap every unmanaged class function. Unmanaged library is added to C++/CLI project using linker dependencies list, and not as reference. In the Project - Properties - Linker open Additional Dependencies and add .lib name there.
注:因为我们是在谈论C ++ / CLI包装,没有PInvoke的!的PInvoke用于调用导出函数(API),而不是类。
Note: since we are talking about C++/CLI wrapper, no PInvoke! PInvoke is used to call exported functions (API), and not classes.
这篇关于创建简单的C ++ .NET的包装。一步步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!