Question

I have this line of codes in C++

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

And call it

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

What's is the equivalent of int * and HANDLE * in C# ?

I have converted it to this code in C# using DllImport. But it's not work.

[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);

I call it

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

Error raised:

enter image description here

Was it helpful?

Solution

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

is

[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);

Depending on what the function does, you might want to replace ref with out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top