title: Passing an unmanaged C++ structure by reference to a managed C++ method causes an access violation when the structure is referenced
body: <p>I'm trying to pass this structure:</p>
  
  <pre><code>#pragma unmanaged
  typedef struct
  {
     void* data;
     unsigned nlen;
     unsigned int type; 
  } PARAMETER;
  </code></pre>
  
  <p>To this class static method:</p>
  
  <pre><code>#pragma managed
  private class __gc GlobalFunctions
  {
     static void WriteField(Object* object, PARAMTER&amp; par, unsigned dec)
     {
         switch (par.type)
         {
            ....
         }
     }
  };
  </code></pre>
  
  <p>From this function:</p>
  
  <pre><code>public class __gc WorkerClass
  {
     void SetValueAt(long index, Object* value)
     {
        PARAMETER aux;
        aux.type = 3;
        GlobalFunctions::WriteField(value, aux, 0);
     }
  };
  </code></pre>
  
  <p>On a 64-bit system, I get an access violation saying that the address '0x000c' cannot be read.</p>
  
  <p>Now, on a 64-bit system, the dereference of par.type would be address of 0x0c if the reference of par was a null pointer. Except par is on the stack - I'm not passing a null pointer into WriteField, but I seem to be getting one out.</p>
  
  <p>Now, in Managed C++, when calling from one managed class instance method to another static method, is the fact that I'm passing an <em>unmanaged</em> structure by reference vulnerable to some sort of marshalling issue?</p>
  
  <p>Is there any web documentation explaining how unmanaged structures are treated by managed code?</p>