Hi, welcome to the boards. For future reference a question about windows api function can elict more responses on the windows board.
In the processes you create(output processes) you need to:
- Create a mailslot.
- Listen on that mailslot.
- Write to output when told to.
In the master process you need to:
- Create the output processes.
- Connect to their mailslots.
- Write to their mailslots to tell them to continue.
Sample for output process:
Code:
int main(void)
{
HANDLE hSlot = CreateMailslot("\\\\.\\mailslot\\msname", 0, MAILSLOT_WAIT_FOREVER, NULL);
while (TRUE)
{
ReadFile(hSlot, buf, sizeof(buf), &dwRead, NULL); // Receive message from master.
printf("%s", buf); // print what the master has told us to.
}
}
Sample for master process:
Code:
int main(void)
{
// Create Processes
// Connect to mailslots.
hSlot1 = CreateFile("\\\\.\\mailslot\\msname", ...);
// Write to mailslots what you want them to output.
WriteFile(hSlot1, "test", 4, ...);
}
Things to think about:
- You need a different name for each mailslot (maybe pass the name you want the output process to use on the command line).
- You need to make sure that the master process does not try to connect to a mailslot before it is created.