简体   繁体   中英

Convert IntPtr to an object C#

From my legacy application (running under seperate process) I am sending double values in an object like this

#define MYMESSAGECODE (WM_APP + 123 )
typedef struct
{
    float f;
    double d;
} MyDataStruct;

MyDataStruct data;
data.f = 1.0;
data.d = 2.0;
pWpfWnd->SendMessage( MYMESSAGECODE, 0, (LPARAM) &data );

This is received in a WndProc in a seperate process Like this

private IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
      switch (msg)
      {
           case GA_SLOT_COORDINATES:
           // Need solution here to convert lParam to MyDataStruct
      }
      return IntPtr.Zero;
}

I want to convert the data passed in lParam from my legacy application to same object in my .Net application running under different process. How can I achieve that? Thanks!!

If you are intra process Marshal.PtrToStructure will help you.

It seems you're trying to do this across the process, that's not possible. Your LParam is a pointer to memory in another process, you can't share memory just like that. You need to use any of Inter process communication techniques. Take a look at Wm_CopyData .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM