从32位C#PostMessage的PARAMS到64位C ++ [英] PostMessage params from 32-bit C# to 64-bit C++

查看:484
本文介绍了从32位C#PostMessage的PARAMS到64位C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有作为的wParam从32位C#应用程序传递一个指针的内容是沿途64位C ++程序改变的问题。

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

有两个进程32.exe(在C#)和64.exe(在C ++)。 64.exe开始为32.exe的一个子进程。为64.exe 32.exe交窗口消息,其中之一具有的wParam是一个指向RECT结构的数组。无论64.exe和32.exe有一个共同的DLL(用C ++编写,但编为不同的平台,当然),被称为32.DLL和64.dll。

There are two processes 32.exe (in C#) and 64.exe (in C++). 64.exe is started as a child process of 32.exe. 32.exe post window message for 64.exe, one of which has a wParam that 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.

期待一个RECT *在32.DLL一个功能是直接从32.exe具有相同RECT *就是后来所谓的发布,这效果很好。此后,它发布消息给64.exe,它调用相同的功能,铸就的wParam到RECT *:

A function expecting a RECT* in 32.dll is called directly from 32.exe with the same RECT* that is later posted, and this works well. Afterwards it posts a message to 64.exe, which calls the same function and casts the wParam to RECT*:

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



该消息公布如下:

The message is posted as follows:

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



通过调试我已经证实,收到消息,但是wParam参数地址是不一样的以前。这并不令人意外,但内存的它指向的内容是不确定的(我也得到尝试,看看还有什么时候访问冲突)。

By debugging I've validated that the message is received, however the wParam address is not the same as it was before. This is not unexpected, but the contents of the memory it now points to is undefined (and I get an access violation when attempting to see what is there).

什么是发生在这里?

推荐答案

这两个过程都有一个自己的地址空间,因此从工艺32.exe指针不在64.exe有效。

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

然而,这无关,与32位VS 64位的。你只需要使用你选择的进程间通信技术来两个进程之间传输数据。

However, this has nothing to do with 32bit vs 64bit at all. You just have to use an interprocess communication technique of your choice to transfer the data between the two processes.

例如,你可以使用的的CreateFileMapping 创建共享内存命名的部分。

For example, you could use CreateFileMapping to create a named section of shared memory.

这篇关于从32位C#PostMessage的PARAMS到64位C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆