【发布时间】:2018-07-20 21:53:52
【问题描述】:
首先:如果标题有误,我很抱歉。我不确定如何命名我的问题。
在我的 C API 中,我有一个函数:
MYAPI_STATUS SetParam(void *hInst, unsigned long param, void *value);
此函数根据param 类型接受不同类型的指针。像这样:
SetParam(hInst, 1, (void*)"somevalue");
int x = 55;
SetParam(hInst, 2, &x);
我只是在 C# 中编写一个包装器/绑定,但我遇到了问题。
[DllImport("myapi", CallingConvention = CallingConvention.Cdecl]
public static extern uint SetParam(IntPtr hInst, uint paramCode, IntPtr paramValue);
从 C 复制行为的最佳方法是什么?所以函数看起来像:
public static uint SetParam(IntPtr hInst, uint paramCode, ref object paramValue);
或者可能:
public static uint SetParam(IntPtr hInst, uint paramCode, object paramValue);
【问题讨论】: