title: Import MQIC.DLL in C#
body: <p>In my system, I need to load MQIC.DLL (IBM WebSphere MQ) to send and get messages to a MQ server. </p>
  
  <p>Currently, this service is running in VB5, and I need to upgrade to .Net. When I try to load this library, I get the error:</p>
  
  <p><strong>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</strong></p>
  
  <p>The code:</p>
  
  <pre><code>[DllImport("MQIC.DLL", EntryPoint = "MQCONNstd@16", SetLastError = true)]
  public static extern void MQCONN(string QMgrName, long Hconn, long CompCode, long Reason);
  </code></pre>
  
  <p>Does anybody have idea why it's happening?</p>
  
  <p>The VB5 code:</p>
  
  <pre><code>Declare Sub MQCONN Lib "MQIC.DLL" Alias "MQCONNstd@16" (ByVal QMgrName As String, Hconn As Long, CompCode As Long, Reason As Long)
  </code></pre>
  
  <p>This is MQOD struct:</p>
  
  <pre><code>public struct MQOD
  {
      public String StrucId; //Structure identifier'
      public long Version; //Structure version number'
      public long ObjectType; //Object type'
      public string ObjectName; //Object name'
      public string ObjectQMgrName; //Object queue manager name'
      public string DynamicQName; //Dynamic queue name'
      public string AlternateUserId; //Alternate user identifier'
  }
  </code></pre>