名帅双字符指针返回值 [英] Marshal a double char pointer return value
问题描述
我使用的是C库具有它返回一个指向char指针数组的功能:
A C library I'm using has a function which returns a pointer to an array of char pointers:
extern char** getIds();
使用的例子:
char **list, **list_save;
list_save = list = getIds();
while (list && *list)
{
printf("Id: %s\n", *list);
list++;
}
freeIds(list_save);
其中, freeIds
也由C库,并释放在 getIds
分配的内存。
Where freeIds
is also from the C library, and frees the memory allocated during getIds
.
他们提供了一个.NET互操作程序集过,但它不会导入 getIds
功能。我有机会获得Interop程序集源$ C $ C。
They provide a .Net Interop assembly too, but it doesn't import the getIds
function. I have access to the interop assembly source code.
我的计划是在C#,所以我想知道是否可以将导入添加到互操作程序集以及它应该是什么样子,还有什么我的C#code必须像调用的函数
My program is in C# so I'd like to know if it possible to add a import to the interop assembly and what it should look like, as well as what my C# code must look like to call the function.
我对DLL导入的猜测是:
My guess for the dll import is:
[DllImport("foo.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr getIds();
但我一直没能得到C#来称呼它,所以我不知道如果DLL进口是正确的。
But I haven't been able to get C# to call it, therefore I don't know if the dll import is correct.
推荐答案
有一个看的封送炭** 。您dllimport的应该工作。
Have a look at Marshaling char**. Your dllimport should work.
这篇关于名帅双字符指针返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!