C *中的int *和HANDLE *等价物

时间:2014-03-26 06:24:18

标签: 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

1 个答案:

答案 0 :(得分:2)

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