C# 调用非托管dll提供接口参数 结构类型 的转换问题。

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).


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值