Just so I understand you right. The "MSGHANDLE *lphContext" parameter is a) used by the external function and/or b) set by the external function?
I think from what you're saying is that it is set by the function. You connect to the Message and it returns a handle to it if successful.
I've never done this before but I think what you need to do is allocate a piece of memory for the pointer to be stored in. So I suggest removing the 'ref' modifier on the lphContext parameter and just have it as an IntPtr.
Before calling the function you need to create the memory for the new handle.
Code:
IntPtr lphContext = Marshal.AllocHGlobal(IntPtr.Size);
IntPtr actualHandle;
Marshal.WriteIntPtr(lphContext, IntPtr.Zero);
MsgConnect(/*ver*/1, /*topic*/"blah", /*operator*/someOperator, lphContext);
// if successful
actualHandle = Marshal.ReadIntPtr(lphContext);
Basically this creates a block of memory for the handle and POINTS lphContext at that block. You can then read and write from that block using ReadIntPtr and WriteIntPtr.
If I've understood correctly this should solve your problem.
P.S. Don't forget to remove the "ref" from the lphContext parameter declaration.
Kep.