title: IntPtr C# to C++ void*
body: <p>I am a beginner in C# and I have been asked to create a C# code which uses a C++ DLL.</p>
  
  <p>Functions from C++ DLL need a void* parameter so I send a <code>IntPtr</code> parameter from the C# code. </p>
  
  <p>But at the end of this function my pointer seems to be <code>NULL</code>. Am I missing something?</p>
  
  <p>Here my C# code:</p>
  
  <pre><code>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"); // 
  }
  </code></pre>
  
  <p>And here is my function from the C++ DLL:</p>
  
  <pre><code>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, &amp;devPath, &amp;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
  }
  </code></pre>
  
  <p>Any help would be very appreciate.</p>