Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access char*** from dll import in C#

Tags:

c#

dll

dllimport

I have a function in win32 dll with signature as:

void func1(int a, char*** outData)

int a --> input parameter
char*** outData --> output parameter - pointer to array of char strings


Any idea how to access this in C# using dll import & what should be the signature.

like image 250
mavrick23 Avatar asked Nov 05 '22 14:11

mavrick23


1 Answers

For complicated types like triple pointers, I find the best approach is to go simple and marshal it as just a IntPtr

[DllImport("Some.dll")]
private static extern void func1(int a, out IntPtr ptr)

Once this function returns the IntPtr value will essentially represent a char**.

Using that value is nearly impossible though because we don't know the length. You'll need to alter your function signature to pass back out the length of the array before it can be used in managed code.

like image 179
JaredPar Avatar answered Nov 14 '22 06:11

JaredPar