我想在 Unity3d 中使用 C++ 代码。通常,没关系,我可以通过导入 dll 来完成。我想了解的是,是否可以使用 C++ 方法参数作为引用传递?
我想做的是获取由 C++ 代码返回的 uchar* 数组的大小。
最佳答案
What i'm trying to learn is whether using C++ method parameters as pass by reference is possible or not?
是的,这是可能的。在 C++ 端使用 int*
,在 C# 端使用 ref int
。您应该能够从 C++ 写入该参数,它将在 C# 端更新。
参见 this从我的另一篇文章中回答一个完整的例子。
What i'm trying to do is getting size of uchar* array returned by c++ code.
你可以用上面的例子。如果您关心性能,请不要从 C++ 返回数组。在 C# 中创建数组,然后将其传递给 C++ 并在那里进行修改。有关信息,请参阅链接的答案。
关于c# - unity3d import c++ dll for pass by reference 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49107988/