title: How do I marshal a structure as a pointer to a structure?
body: <p>I am trying to pass a structure from C# into C++ library. I pass structure as an object, and C++ function expects it as a pointer (void *).  </p>
  
  <p>I am having problem passing the structure.</p>
  
  <pre><code>[DllImport("MockVadavLib.dll", CharSet = CharSet.Ansi)]
  public static extern IntPtr TheFunction([MarshalAs(UnmanagedType.LPStruct)] UserRec userRec);
  </code></pre>
  
  <p>Here is the run-time exception text I get:</p>
  
  <blockquote>
    <p>"Cannot marshal 'parameter #1': Invalid managed/unmanaged type combination (this value type must be paired with Struct)."</p>
  </blockquote>
  
  <p>Though I found an MSDN article that uses LPStruct in exactly this context.</p>
  
  <p>This is my structure I'm trying to marshal:</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
  public struct UserRec {
      [MarshalAs(UnmanagedType.I4)]
      public int userParam1;
  }
  </code></pre>
  
  <p>This is C++ function:</p>
  
  <pre><code>MOCKVADAVLIB_API tVDACQ_CallBackRec * TheFunction(void * userParams) {...
  </code></pre>