[英]Win32 Inter Process Communication Assignment
I need to do a C++ assignment, but I'm pretty much new to Win32 IPC.我需要做一个 C++ 任务,但我对 Win32 IPC 还很陌生。 I did a little bit of research yesterday, but I cannot find the thing I'm searching for.
我昨天做了一些研究,但找不到我要找的东西。
Basically, I need two programs, the first creates a FileMapping with paging file, waits a buffer, display the buffer, and closes it.基本上,我需要两个程序,第一个创建一个带有分页文件的 FileMapping,等待缓冲区,显示缓冲区,然后关闭它。
The second connects to the Communication Channel, writes the buffer to the first program, and then closes.第二个连接到通信通道,将缓冲区写入第一个程序,然后关闭。
The closest thing I've come to is this resource: IPC Communication but the guy there uses pipes instead of communication channels using paging file.我最接近的是这个资源: IPC 通信但是那里的人使用管道而不是使用页面文件的通信通道。
Also, I found that I can open a FileMapping with paging file pretty much like this:另外,我发现我可以打开一个带有分页文件的 FileMapping,就像这样:
TCHAR szMapFileName[] = _T("Local\\HelloWorld");
HANDLE hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE,
NULL, // Default security
PAGE_READWRITE, // Read/write access
0, // Max. object size
BUFFER_SIZE, // Buffer size
szMapFileName // Name of mapping object);
If somebody can provide a little help that would be very valuable(maybe a skeleton of an app?).如果有人可以提供一些非常有价值的帮助(也许是应用程序的框架?)。 I tried to do some research yesterday, but in vain.
昨天我试图做一些研究,但徒劳无功。
Thanks谢谢
CreateFileMapping()
, OpenFileMapping()
and MapViewOfFile()
are indeed the functions you need to call to allocate a shared memory buffer. CreateFileMapping()
、 OpenFileMapping()
和MapViewOfFile()
确实是您需要调用以分配共享 memory 缓冲区的函数。
The first app must:第一个应用程序必须:
WM_APP+nnn
) to the main thread, to display the contents of the buffer.WM_APP+nnn
) 发布到主线程,以显示缓冲区的内容。 The second app must:第二个应用程序必须:
It could be further improved, eg the second app may not write to the buffer if the event is not in the nonsignaled state.它可以进一步改进,例如,如果事件不在未发出信号的 state 中,则第二个应用程序可能不会写入缓冲区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.