I am working on C#.Net application which uses C-based library. As it needs C# Wrapper I am implementing code to marshal functions from C-based library to be accessible in C# and map data type correctly.
I have a function in library which Takes A char array by reference, The function contains logic to update array with values in it. So, At function call we can pass null array and access result value after its been called.
Objective: to pass null char array and return value by reference
The C-dll function:
int function_call(char ** var);
The C function call code:
char *name = NULL;
int val = function_Call(&name);
The C# wrapper code:
[DllImport("mylibrary.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int function_call([In] string[] val);
The C# function call code:
string[] name = null;
int ret = function_call(name);
I came across similar queries :
- How to get char** using C#? [duplicate]
How do I marshal a pointer to an array of pointers to structures?
Tried all of them but did not work. returns null value. Is there a simple working way to marshal Char ** ?