PostMessage options from 32-bit C # to 64-bit C ++

I am having a problem with the contents of a pointer passed as wParam from a 32-bit C # application, changing along the way to the 64-bit C ++ process.

There are two processes: 32.exe (in C #) and 64.exe (in C ++). 64.exe starts as a child process of 32.exe. 32.exe post window message for 64.exe, one of which has wParam, which is a pointer to an array of RECT structures. Both 64.exe and 32.exe have a common DLL (written in C ++, but compiled for different platforms, of course), called 32.dll and 64.dll.

A function that expects RECT * in 32.dll is called directly from 32.exe with the same RECT * that was later sent, and this works well. Then it sends a message to 64.exe, which calls the same function and passes wParam to RECT *:

else if (WM_SetDisabledAreas == message)
{
    SetDisabledAreas((RECT*)wParam, (UINT)lParam);
}

The message is published as follows:

    if (Is64Bit() && SubProcess64 != null)
    {
        Win32.PostMessage(SubProcess64.MainWindowHandle, WindowMessages.SetDisabledAreas,
            (uint)pointer.ToInt32(), length);
    }
    MessageBox.Show(pointer.ToString());
    DLL32.SetDisabledAreas(pointer, length);

Debugging I confirmed that the message was received, however the wParam address does not match the previous one. This is not unexpected, but the contents of the memory that it points to now are undefined (and I get an access violation when I try to see what is there).

What's going on here?

+2
source share
1 answer

Each of the two processes has its own address space, so the pointer from the 32.exe process is not valid in 64.exe.

However, this has nothing to do with 32-bit and 64-bit. You just need to use the interprocess communication technique of your choice to transfer data between the two processes.

, CreateFileMapping .

+5

Source: https://habr.com/ru/post/1623279/


All Articles