在 C# 中使用 C++ API [英] Using C++ API in C#

查看:56
本文介绍了在 C# 中使用 C++ API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用用 C++ 编写的 API.它涉及包括头文件和库.如何在 C# 应用程序中使用此 API?

I would like to use an API that is written in c++. It involves including header files and libraries. How can I use this API in a C# application?

推荐答案

最简单的方法是在 C++/CLI.这让您可以将非托管接口和托管代码混合在一起,以便您可以将非托管 API转换"为托管代码中可使用的 API.

The easiest way is to write a 'shim' assembly in C++/CLI. This lets you mix the unmanaged interface and managed code together so you can 'translate' the unmanaged API into some that is consumable in managed code.

那里有很多资源,要深入了解,请参阅 C++/CLI基本原理以及关于互操作问题的讨论,请尝试在 .NET 到 C++ 桥.

There are lots of resources out there, for an in depth overview see C++/CLI Rationale and for a discussion of the interop issues try this post on a .NET to C++ Bridge.

这篇关于在 C# 中使用 C++ API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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