简体   繁体   English

将 C# 字符串数组传递给 C++

[英]Passing a C# String array to C++

I have a string array in C# for example:例如,我在 C# 中有一个字符串数组:

string[] level = {"results","isPA"}

Now I need to pass this array to a C++ Function.现在我需要将此数组传递给 C++ Function。

The wrapper looks like this:包装器看起来像这样:

[DllImport("File.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)

public static extern long SetJsonString(string[] Level, string Entry, string Item);

The C++ function then gets called using:然后使用以下命令调用 C++ function:

long SetJsonString(char** Level, char* Entry, char* Item)

If I know want to access the single elements of the array I only get the first one.如果我知道想要访问数组的单个元素,我只会得到第一个。 Does anybody have some ideas how to handle the passing?有人对如何处理传球有一些想法吗?

Using SafeArray just like Thinh Tran suggested did the trick.就像Thinh Tran建议的那样使用 SafeArray 就可以了。

The code can be found here: codeproject in the "Passing an Array of Strings" paragraph.可以在此处找到代码:“传递字符串数组”段落中的codeproject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM