IntPtr C#至C ++ void *

时间:2019-03-13 09:26:39

标签: c# c++ void intptr

我是C#的初学者,被要求创建使用C ++ DLL的C#代码。

C ++ DLL中的函数需要一个void *参数,因此我从C#代码发送了一个IntPtr参数。

但是在该函数结束时,我的指针似乎是NULL。我想念什么吗?

这是我的C#代码:

int somme = 0;
IntPtr deviceHandle = new IntPtr();
uint[] SpiConf = new uint[7];
somme = Opening(deviceHandle, SpiConf);
if (deviceHandle == IntPtr.Zero)
{
    Console.WriteLine("deviceHandle is NULL"); // 
}

这是C ++ DLL中的函数:

int Opening(void* deviceHandle, unsigned char SpiConf[])
{
    wchar_t devPath;
    unsigned long devPathsize = 0;
    unsigned short VID = 0x4d8;
    unsigned short PID = 0xde;
    int res;

    deviceHandle = Mcp2210_OpenByIndex(VID, PID, 0, &devPath, &devPathsize);
    res = Mcp2210_GetLastError();
    if (res != E_SUCCESS)
    {
        //Console.WriteLine("Failed to open connection");
        return -1;
    }
    if (deviceHandle == NULL)
    {
        return -2;
    }
    return 0; // This function returns 0
}

任何帮助将不胜感激。

0 个答案:

没有答案