ddup_fswx6
ddup_fswx6
2018-08-18 14:45

c# 调用c++ sdk 传结构体指针

5
  • c#
  • c++
  • sdk
  • 结构

本人菜鸟一枚
SDK函数 LIBBVCU_API BVCU_Result BVCU_Initialize( const BVCU_GlobalParam* pParam);

其中 BVCU_GlobalParam为结构体
typedef struct _BVCU_GlobalParam
{

int iSize;
void (*OnEvent)(int iEventCode, void* pParam);
int iReserved[4];
}BVCU_GlobalParam;

问题我是该直接传递一个指针,还是传一个BVCU_GlobalParam类型参数
public IntPtr m_bvcuSdkHandle;
BVCU_Initialize(ref Im_bvcuSdkHandle)(指针)
还是 BVCU_Initialize(ref _BVCU_GlobalParam bg) (结构体)

 [DllImport("libBVCU.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern int BVCU_Initialize(ref IntPtr handle);

[StructLayout(LayoutKind.Sequential)]
    public struct BVCU_GlobalParam
    {
        public int iSize;
        public CallbackDelegate OnEvent;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
        public int[] iReserved;

    };

这两种都试了,接口返回还是参数不符合,请大神上码指教

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答