简体   繁体   中英

Processes communicating through named shared memory

I made 2 Visual Studio projects that communicate through a mapped file. 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). Then I have to start B, which will read the file and print whatever is in it. 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).

My question is: is there a way to start my project B through A, without me needing to run project B manually?

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:

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) ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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