创建简单的c ++ .net包装器。一步步 [英] Creating simple c++.net wrapper. Step-by-step

查看:129
本文介绍了创建简单的c ++ .net包装器。一步步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++项目。我承认我在c ++中完全是零。但是我仍然需要编写一个c ++。net wrapper,所以我可以使用一个非托管的c ++库。所以我有:
1)非管理项目的头文件。
2)非托管项目的库(.dll和.lib的)
3)我打算用作我的c#应用程序的包装器的空C ++ .NET项目



我如何开始?我甚至不知道如何设置对非托管库的引用。



SOS

解决方案

http://www.codeproject.com/KB/mcpp/quickcppcli.aspx#A8



这是一般方向。您需要创建C ++ / CLI类库项目,向其中添加.NET类(此示例中为StudentWrapper),将非托管类实例创建为托管类成员,并包装每个非托管类函数。非管理库使用链接器依赖列表添加到C ++ / CLI项目中,而不是作为参考。在项目 - 属性 - 链接器中打开其他依赖关系并在其中添加.lib名称。



注意:由于我们在谈论C ++ / CLI包装器,没有PInvoke! PInvoke用于调用导出的函数(API),而不是类。


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.

解决方案

http://www.codeproject.com/KB/mcpp/quickcppcli.aspx#A8

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.

Note: since we are talking about C++/CLI wrapper, no PInvoke! PInvoke is used to call exported functions (API), and not classes.

这篇关于创建简单的c ++ .net包装器。一步步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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