DOCERR: CreateFile() and Mailslots

ID: Q131493

The information in this article applies to:

SUMMARY

The documentation for CreateFile() API gives incorrect possible return values while opening a client end of a mailslot. The documentation states:

    If CreateFile opens the client end of a mailslot, the function always
    returns a valid handle, even if the mailslot does not exist.
    In other words, there is no relationship between opening the client
    end and opening the server end of the mailslot.

Actually, CreateFile() returns INVALID_HANDLE_VALUE for a mailslot if the mailslot client is being created using the "\\." notation to communicate with a mailslot server on the local system when the server is not up and running.

MORE INFORMATION

The following code always returns INVALID_HANDLE_VALUE for a handle value from CreateFile() while opening the client end of the mailslot if the mailslot server is not up and running to read mailslot messages:

    CreateFile("\\\\.\\mailslot\\testslot",
               GENERIC_WRITE,
               FILE_SHARE_READ,
               NULL,
               OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL,
               NULL);

GetLastError() in this case returns Error 2: "The system cannot find the specified file."

This is an expected behavior. Windows NT implementation of local mailslots does not allow you to open the mailslot if the receiver has not created the server end with CreateMailslot() API.

Additional query words: Keywords : kbnetwork kbdocerr kbAPI kbIPC kbNTOS350 kbSDKPlatform kbMailslot kbGrpNet

Last Reviewed: July 31, 1998