C ++中的消息传递和接收 [英] Message Passing and receiving in c++

查看:74
本文介绍了C ++中的消息传递和接收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要将消息发送到另一个应用程序,并使用LPARAM传递字符串

正在发送申请:

Hi,

I need to send a message to another application and pass a string using LPARAM

Sending Application:

const UINT WM_GAURD_WINPROC = RegisterWindowMessage( "GAURD");
char name[MAX_PATH] = "E:\Net-Worm\Groups\Worm\Worm.Win32.Socks.gh";
SendMessage(HWND_BROADCAST,WM_GAURD_WINPROC,NULL,(LPARAM)name);




接收申请




Receiving Application

void __fastcall TForm1::WndProc( TMessage& Message)
{
if(Message.Msg == WM_GAURD_WINPROC)
{
        ShowMessage("Msg Recieved");
        char *s = (char *)(Message.LParam);
	if (strcmp(s,"E:\Net-Worm\Groups\Worm\Worm.Win32.Socks.gh")==0) {
			Scan(s);
	}
	ShowMessage(s);
}
}



显示了已接收邮件",但是我尝试发送的字符串似乎没有意义.我应该如何传递此参数,以及如何在接收应用程序中使用它?
顺便说一下,我正在使用C ++ Builder.
谢谢.



The "Msg Recieved" is shown but the string that I''m trying to send seems to be nonesense. How should I pass this parameter and also how can I work with it in the receiving application?
By the way, I am working in C++ builder.
Thanks.

推荐答案

问题所在行:
problem with the line :
char name[MAX_PATH] = "E:\Net-Worm\Groups\Worm\Worm.Win32.Socks.gh";
//you are actually getting: 
"E:Net-WormGroupsWormWorm.Win32.Socks.gh"



我认为,另一个问题是名称是一个局部变量,但我不确定,您的第二个应用程序无法正确访问该地址.据我所知OS不会允许您访问.

您最好遵循上述建议,否则您可以分配全局内存.



Another issue is name is a local variable, I think, but not sure, your second application is not getting proper access to that address. as far I know OS wont allow you to access.

You better follow the above suggestion or you can allocate global memory.


我在这里看到了其他内容...

``\''字符是C/C ++中的控制字符.
如果要将其表示为字符串文字,请使用"\\".

试试这个:

char name [MAX_PATH] ="E:\\ Net-Worm \\ Groups \\ Worm \\ Worm.Win32.Socks.gh";
I see something else here...

The ''\'' character is a control character in C/C++.
If you want it expressed as a string literal then use, ''\\''.

Try this:

char name[MAX_PATH] = "E:\\Net-Worm\\Groups\\Worm\\Worm.Win32.Socks.gh";


看到HWND_BROADCAST,我想您正在发送如果第二个应用程序是另一个进程,则无法在函数中发送局部变量的地址.每个进程都有自己的内存空间.

可能的解决方案:使用进程间工具,例如pipe/files/sockets,您可以从codeproject中获得有关这些工具的大量信息.
By seeing HWND_BROADCAST i guess you are sending this message to an another process.If the second application is a different process, you cannot send the address of a local variable in your function. Each process has its own memory space.

Possible solutions: use inter process tools like pipe/files/sockets , you can get plenty of information about these from codeproject.


这篇关于C ++中的消息传递和接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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