I am implementing c#.net wrapper for C-based Library. currently, working on function with passing A void pointer, which will set value.
NOTE : void pointer can take different data type depending on Enum.
Objective: to pass void pointer and set value
I checked many solutions to implement and finally came to following state :
The C-dll function:
int function_call(enum a, void * var);
The C function call code:
char name[255];
name = "asd";
function_call(enum a, &name);
The C# wrapper code:
[DllImport("mylibrary.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int function_call(enum a, IntPtr var);
The C# function call code:
IntPtr name;
string val = "asd";
name = Marshal.StringToHGolbalUni(val);
int ret = function_call(Enum_type, name);
By this method it only sets First character
a
from the inputasd
.
I have already checked "Duplicate" questions but doesnt solve the issue: