Mailslots in Windows are supported by three specialized functions: CreateMailslot, GetMailslotInfo, and SetMailslotInfo. These functions are used by the process that creates the mailslot.
The following function uses the CreateMailslot function to retrieve a handle to a mailslot named slot1.slt:
BOOL FAR PASCAL Makeslot(HWND hwnd, HDC hdc)
{
LPSTR lpszSlotName = "\\\\.\\mailslot\\slot1.slt";
/* Mainslot handle "hSlot1" is declared globally. */
hSlot1 = CreateMailslot(lpszSlotName,
0, /* no maximum message size */
MAILSLOT_WAIT_FOREVER, /* no timeout for read operations */
(LPSECURITY_ATTRIBUTES) NULL); /* no security attributes */
if (hSlot1 == INVALID_HANDLE_VALUE) {
ErrorHandler(hwnd, "CreateMailslot"); /* local error handler */
return FALSE;
}
TextOut(hdc, 10, 10, "CreateMailslot successful.", 26);
return TRUE;
}
All mailslots are local to the process that creates them; a process cannot create a remote mailslot.
An application can create a mailslot that is inherited by child processes by changing the SECURITY_ATTRIBUTES structure passed as the last parameter of the CreateMailslot function. To do this, the application should set the bInheritHandle member of this structure to TRUE. (The default setting is FALSE.)