开发者

What's the easiest way to send a string to another application? (Win API)

I have two Win32 API programs written in plain C: Program A and program B. I want program B to send the string "Hello World" to program A. So B needs to do the following:

1) Detect if program A is running.

2) If it is, send "Hello World" string to A.

3) If A is not running, B 开发者_开发知识库should show an error message.

Can someone point me to the API functions necessary to do this? How would I establish such a communication between two programs? I think the biggest problem is that the "Hello World" string is in the address space of program B and it somehow needs to move to the address space of A. So just passing a memory pointer is not sufficient... I need a different approach. Any ideas?

Thanks


To find the other program's main window I recommend using FindWindow or EnumWindows. Which one you use depends on just what you know about the other process.

Once you have that the easiest way to send text data is via a WM_COPYDATA windows message.

To show an error message, use MessageBox.


Google for WM_COPYDATA. Failing that, you could use a UDP message over the local IP stack or a pipe.


This tutorial might be helpful: http://ryanfarley.com/blog/archive/2004/05/10/605.aspx

It even has a downloadable sample program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜