title: C++/CLI: Passing C++ class ptr to unmanaged method
body: <p>I've been given a third party C/C++ library (.dll, .lib, .exp and .h) that I need to use in our C# app.  </p>
  
  <p>ThirdPartyLibrary.h contains...</p>
  
  <pre><code>class AClass {
   public:
    typedef enum {
        green = 7,
        blue = 16
    } Color;
    virtual int GetData()=0;
    virtual int DoWork(Color, char *)=0;
  };
  
  void * Func1(int, AClass **aClass);
  </code></pre>
  
  <p>In my C++/CLI code I have done this...</p>
  
  <pre><code>#include "ThirdPartyLibrary.h"
  using namespace System;
  using namespace System::Runtime::InteropServices;
  
  namespace Wrapper {
  public ref class MyBridgeClass
  {
  private:
    AClass* pAClass;
  
  public:
    // C# code will call this method
    void AMethod (int x)
    {
      int y = x+10;
      Func1 (y, &amp;(this-&gt;pAClass));  // &lt;-- error!
    }
  }
  }
  </code></pre>
  
  <p>I get a build error that reads...</p>
  
  <pre><code>cannot convert parameter 2 from 'cli::interior_ptr&lt;Type&gt;' to 'AClass **'
        with
        [
            Type=AClass *
        ]
        Cannot convert a managed type to an unmanaged type
  </code></pre>
  
  <p>Any ideas?  Maybe I need #pragma manage/unmanged tags in my C++/CLI?</p>