C# 调用非托管dll提供接口参数 结构类型 的转换问题。
You can pass and receive structure parameters using the MarshalAs attribute with the UnmanagedType.LPStruct enumeration, but in the function iaxc_audio_devices_get, we need special care. Look at the function signature:
EXPORT int iaxc_audio_devices_get(struct iaxc_audio_device **devs,
int *nDevs, int *input, int *output, int *ring);
The function needs a pointer to a pointer parameter (indicated by **). C# doesn't have a UnmanagedType option to use with this kind of a parameter, and we need a workaround here:
[DllImport(DllImportName, CallingConvention = CallingConvention.StdCall)]
public static extern int iaxc_audio_devices_get(
ref IntPtr devs,
ref int nDevs,
ref int input,
ref int output,
ref int ring);
The IntPtr type is a specific type that represents a pointer, and we can use it to represent the 'a pointer' part of the parameter. The first part, 'a pointer to' can be achieved using the ref parameter attribute, specifying that the parameter is a reference parameter used normally in C# code. So, ref IntPtr means a pointer ( ref ) to a pointer (IntPtr).