In my system, I need to load MQIC.DLL (IBM WebSphere MQ) to send and get messages to a MQ server.
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:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
[DllImport("MQIC.DLL", EntryPoint = "MQCONNstd@16", SetLastError = true)]
public static extern void MQCONN(string QMgrName, long Hconn, long CompCode, long Reason);
Declare Sub MQCONN Lib "MQIC.DLL" Alias "MQCONNstd@16" (ByVal QMgrName As String, Hconn As Long, CompCode As Long, Reason As Long)
Change the declaration of
MQCONN to use
out long for all
Check MQ application programming reference for each API call, and make sure you use
ref for every parameter described as output or input/output.
You can also look for
cmqc.h in your MQ installation directory, provided you have installed development environment. It has declarations of all MQI calls. You can transcribe the C header to C# - wherever you see a pointer (
But generally speaking, you are going to be much better off using managed .Net classes for MQ, as others suggested.