I have a large library written in C that I would like to use as a DLL in a C# program. Most of the C code will be used by the libraries own functions, but I do need one function to be able to be called from the C# project.
So there's an example C function below
__declspec(dllexport) char* test(char* a){
char* b = "World";
char* result = malloc(strlen(a) + strlen(b) + 1);
strcpy(result, a);
strcpy(result, b);
return result;
}
Now in the C# code I have got using System.Running.InteropServices;
and also [DllImport("mydll.dll")]
but I'm not sure how to declared the function.
public static extern char* test(char* a);
obviously doesn't work because C# doesn't support pointers like C does.
So how should I pass a string to this C function and have it return a string as well?