I keep getting an AccessViolationException when called from an external C DLL:
short get_device_list(char ***device_list, int *number_of_devices);
I created a DLLImport declaration as such:
[DLLImport("mydll.dll")]
static public extern short get_device_list([MarshalAs(UnmanagedType.LPArray)] ref string[] devices, ref int number_of_devices);
My C # application code:
{
string[] devices = new string[20];
int i = 0;
short ret = 0;
ret = get_device_list(ref devices, ref i);
}
Although I get an exception, the device array is correctly populated with the two UUIDs of the connected devices (and also reduced to size = 2; I also equal 2;).
What's wrong?
PS: After a long research, I also tried:
[DLLImport("mydll.dll")]
static public extern short get_device_list(ref IntPtr devices, ref int number_of_devices);
and
{
IntPtr devices = new IntPtr();
int i = 0;
short ret = 0;
ret = get_device_list(ref devices, ref i);
string b = Marshal.PtrToStringAuto(devices);
}
but it didn’t help me.
Thanks in advance!
source
share