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

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

问题描述

我有一个 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.

求救

推荐答案

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

这是大方向.您需要创建 C++/CLI 类库项目,向其中添加 .NET 类(本示例中的 StudentWrapper),创建非托管类实例作为托管类成员,并包装每个非托管类函数.使用链接器依赖项列表将非托管库添加到 C++/CLI 项目,而不是作为参考.在 Project - Properties - Linker 中打开 Additional Dependencies 并在那里添加 .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 包装器.一步步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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