如何正确使用文件映射并将数据传递给子进程? [英] How to correctly use File Mapping and pass Data to a child process?

查看:185
本文介绍了如何正确使用文件映射并将数据传递给子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式正在执行另一个程序( update.exe ),我想将大量资料(可能是「记录」)从我的应用程式传送到程序。

My application is executing another process ("update.exe"), and I would like to pass large data (a Record maybe) from my app to the update program.

使用命令行传递数据参数不是一个选项,因为数据太大(数据大小也可能不同)。

Using command line to pass the data parameter(s) is not an option, because the data is too big (also Data size may vary).

如何正确创建 CreateFileMapping / MapViewOfFile / UnmapViewOfFile

然后执行我的 update.exe

最后接收 update.exe 程序( OpenFileMapping ),

并释放所有句柄
)所以我没有内存/句柄泄漏?

How to correctly create CreateFileMapping/MapViewOfFile/UnmapViewOfFile,
then Executing my update.exe,
finally Receiving the data in the update.exe program (OpenFileMapping),
and freeing all handles (from main app and update.exe) so I don't have memory/handle leaks?

代码会很好(请不要 JCL )。 C ++也很好。
感谢。

Code would be nice (No JCL please). C++ is also fine. Thanks.

编辑:我认为我的主要问题是如何在读取数据后,在 update.exe 之后的 UnmapViewOfFile CloseHandle (或者也许我需要使用 OpenFileMapping bInheritHandle 设置为 True 在我的子进程中?)

这是一个示例。如果主进程调用 UnmapViewOfFile CloseHandle ?如何,第二个进程如何读取数据?

I think my main problem is how to "signal" the main app to UnmapViewOfFile and CloseHandle after update.exe done reading the data. (or maybe I need to use OpenFileMapping with bInheritHandle set to True in my child process?)
Here is an Example. How can the Second process read the data if the main process calls UnmapViewOfFile and CloseHandle?.

推荐答案

您可以在找到一个很好的例子进程间通信。正确的方法取决于您的数据大小和速度要求。

You may find some good example at Inter-process communication. Right method depends on the size of your data and speed requirements.

这篇关于如何正确使用文件映射并将数据传递给子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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