简体   繁体   English

通过命名共享内存进行通信的进程

[英]Processes communicating through named shared memory

I made 2 Visual Studio projects that communicate through a mapped file. 我制作了两个通过映射文件进行通信的Visual Studio项目。 But I have to start each of them sepparately: First start A, run it (it will create the mapped file and fill it with info). 但是我必须分别启动它们:首先启动A,运行它(它将创建映射的文件并用信息填充它)。 Then I have to start B, which will read the file and print whatever is in it. 然后,我必须启动B,它将读取文件并打印其中的任何内容。 Of course, closing A and running B will not work(B will not find the mapped file since that one is in the memory only while A is running). 当然,关闭A并运行B是行不通的(B不会找到映射文件,因为该文件仅在A运行时才在内存中)。

My question is: is there a way to start my project B through A, without me needing to run project B manually? 我的问题是:有没有一种方法可以通过A启动我的项目B,而无需我手动运行项目B?

Instead of starting manually A and then B you should only start manually program A and let program A start program B with the CreateProcess function: 而不是先手动启动A,然后手动启动B,您只应手动启动程序A,并让程序A使用CreateProcess函数启动程序B:

STARTUPINFO startupinfo ;
startupinfo.cb = sizeof (startupinfo) ;
PROCESS_INFORMATION pinfo ;
memset(&startupinfo, 0, sizeof (startupinfo)) ;
bool success = CreateProcess("b.exe", NULL, NULL, NULL, false, NORMAL_PRIORITY_CLASS,
                             NULL, NULL, &startupinfo, &pinfo) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM