在C#中调用非托管c ++代码与STL混合 [英] Calling unmanaged c++ code in C# Mixed with STL

查看:299
本文介绍了在C#中调用非托管c ++代码与STL混合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想在C#
中调用非托管的c ++代码。函数接口如下所示(我简化了它,以便于理解)

Hey, I want to call unmanaged c++ code in C# The function interface is like following(I simplified it to make it easy to understand)

Face genMesh(int param1, int param2);

Face是一个结构体定义为:

Face is a struct defined as:

struct Face{
    vector<float> nodes;
    vector<int>  indexs;
}

我googled并阅读MSDN文档找到方法调用简单的c / c ++ unmanged代码在C#中,也知道如何处理结构作为返回值。我的问题是如何处理矢量。我没有找到关于向量和一些类型之间的映射的规则在C#

I googled and read the MSDN docs found ways to call simple c/c++ unmanged code in C#, also know how to hand the struct as return value. And My question is how to handle "vector". I did not find rules about mapping between vector and some types in C#

谢谢!

推荐答案

如果可能,您希望避免在纯UNB代码中使用STL。当你与C ++ / CLI(或Managed C ++)混合使用时,你最终可能会得到以托管方式运行的STL代码和以非托管方式运行的客户端代码。发生什么情况是,当你说,在一个向量上迭代时,每一次向量方法的调用都将转换为托管代码,然后再返回。

You want, if possible, to avoid using STL in anything but pure UNmanaged code. When you mix it with C++/CLI (or Managed C++), you will likely end up with the STL code running as managed and the client code running as unmanaged. What happens is that when you, say, iterate over a vector, every call to a vector method will transition into managed code and back again.

请参阅此处提出类似问题。

这篇关于在C#中调用非托管c ++代码与STL混合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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