title: How to hold a List<> of opaque handles in CLI/C++?
body: <p>I am writing a CLI/C++ wrapper for a C-library in order to use it in C#. It must be said, I only have access to the C header file and the .lib of the C-library, not the source code.</p>
  <p>Some of the functions I am trying to wrap are returning opaque handles, such as:</p>
  <pre><code>typedef struct SanEvent_s *SanEvent;
  typedef struct SanValue_s *SanValue;
  </code></pre>
  <p>Returning objects of this type on the C# end seems like trouble to me, as I don't know the implementation of the struct (I tried returning the SanEvent type in the C++ wrapper but on the C# end that type is not accessible due to &quot;protection level&quot; or whatever it said). My plan at the moment is therefore to write some helper functions, which instead just return an integer which represents an, for example, <code>San Event</code> in a list or something. The list would be kept in the managed C++ wrapper, where I can actually manage the <code>San Event</code> type.
  My problem is, I don't really know how to do this with this type of <code>type</code>.</p>
  <p>This:</p>
  <pre><code>using System::Collections::Generic::List;
  namespace Wrapper {
      public ref class Analytics
      {
      private:
          static List&lt;SanEvent^&gt;^ events = gcnew List&lt;SanEvent^&gt;();
      }
  }
  </code></pre>
  <p>Gives me the errors: <em>handle to handle, pointer, or reference is not allowed</em></p>
  <p>The right hand side also complains about <em>expected type specifier</em> + the same error as above.</p>
  <p>Can anyone give me some tips on how I could tackle this issue neatly and efficiently? My List implementation is not carved in stone, and I am open to better suggestions.</p>