c# - int * 和 HANDLE * 在 C# 中等效

标签 c# c++ dllimport

我在 C++ 中有这行代码

WD_OpenDevice(PCSTR szDevPath, HANDLE *phDevice, HANDLE ahChannels[], int *pnChannelNum, int iVideoStandard = WD_VID_STD_PAL, PCSTR szUser = NULL, PCSTR szPswd = NULL);

然后调用它

WD_OpenDevice("xxxxxxxx", &m_hDev, m_ahChannels, &m_nChannelNum);

C# 中 int * 和 HANDLE * 的等价物是什么?

我已使用 DllImport 在 C# 中将其转换为此代码。但这行不通。

[DllImport("WD_SDK.dll", SetLastError = true)]
        static extern int WD_OpenDevice(string szDevPath, IntPtr phDevice, IntPtr[] ahChannels, int pnChannelNum, int iVideoStandard = 1, string szUser = null, string szPswd = null);

我叫它

 IntPtr[] m_ahChannels = new IntPtr[4];
            int m_nChannelNum = 0;
            IntPtr m_hDev = new IntPtr();
            a = WD_OpenDevice("wdvr://localhost/qqdvr", m_hDev, m_ahChannels, m_nChannelNum);

引发的错误:

enter image description here

最佳答案

WD_OpenDevice(PCSTR szDevPath,
              HANDLE *phDevice,
              HANDLE ahChannels[],
              int *pnChannelNum,
              int iVideoStandard = WD_VID_STD_PAL,
              PCSTR szUser = NULL,
              PCSTR szPswd = NULL);

[DllImport("WD_SDK.dll", SetLastError = true, CharSet = CharSet.Ansi)]
static extern int WD_OpenDevice(string szDevPath,
                                ref IntPtr phDevice,
                                IntPtr[] ahChannels,
                                ref int pnChannelNum,
                                int iVideoStandard = 1,
                                string szUser = null,
                                string szPswd = null);

根据函数的作用,您可能希望将 ref 替换为 out

关于c# - int * 和 HANDLE * 在 C# 中等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22653064/

相关文章:

c# - Unity3d,在鼠标位置射击

c# - 我应该将属性声明为接口(interface)还是基类(当它们同时实现时)?

c# - 相等运算符——总是左结合的,这有关系吗?

c# - P/调用 const char 指针和 int 引用

dllimport - 尝试使用 Python.NET 导入 c# dll 时出现 "No module named"错误

c# - 对象当前正在别处使用 - 当 image.save

数组名称的 C++ 值

c++ - 使用 -std=c++0x 导致错误 : ‘Iterator’ does not name a type error

c++ - Qt:QWidget::paintEngine:不应再调用

c# - 在 DllImport 中指定 Charset.Unicode 是否分配字符串?