title: C# calling unmanaged code: "Cannot convert from 'CustomClass' to 'ref System.IntPtr'"
body: <p>I am writing wrapper functions for a c++ library in c#.
  My function in c++ takes two pointers as arguments of which it changes the content one of them points to (<code>foo</code>).
  So in c# I need to pass this as a <code>ref</code> right?
  I have:</p>
  
  <p>C++:</p>
  
  <pre><code>ErrorCode MyFunction(void* dev, void* foo);
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>[DllImport("MyLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
          public static extern ExceptionClass.ErrorCode MyFunction(IntPtr dev, ref IntPtr foo);
  </code></pre>
  
  <p>When I call the function in C# like this</p>
  
  <pre><code>public void CallFunction(DevClass dev, FooClass foo)
  {
    MyFunction(dev, ref foo);
  }
  </code></pre>
  
  <p>I get the Error</p>
  
  <p><code>Error 3   Argument 2: cannot convert from 'ref FooClass' to 'ref System.IntPtr'</code>           </p>