如何在 C# WPF 项目中使用 C++ 库(.lib) [英] how to use c++ libraries(.lib) in c# WPF project

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

问题描述

我有一个在 VC++ 中实现的库(.lib).我想在 c# wpf 项目中包含或使用这个库,我该如何实现.

I have a library(.lib) which as been implemented in VC++. I want to include or use this library in c# wpf project how can i achieve it.

推荐答案

您可以使用 编组 以访问 C# 代码中的 C++ 代码.

You can use marshalling to access C++ code in your C# code.

看看 MSDN 也是.

一个例子

[DllImport("example.dll")]
static public extern void DoSomething(int value);

并且您可以像往常一样在 C# 代码中使用您的方法

and you can use your method in your C# code like usual

DoSomething(42);

可能有点混乱,因为您必须将 C++ 类型映射"到 C# 并反向.

Can be a bit confusing because you have to "map" the C++ types to C# and reverse.

这篇关于如何在 C# WPF 项目中使用 C++ 库(.lib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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