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).
本文探讨了C#中调用非托管DLL时遇到的问题,特别是针对含有双层指针参数的函数iaxc_audio_devices_get。文章详细介绍了如何通过使用ref IntPtr来解决这一问题。
1840

被折叠的 条评论
为什么被折叠?



