A question on mailslot

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: cyberninja (cyberninja_at_discussions.microsoft.com)
Date: 06/10/04


Date: Thu, 10 Jun 2004 16:29:01 -0700

When reading a stream from a mailslot, the following Win32 API is used:

BOOL ReadFile(HANDLE hFile,
  LPVOID lpBuffer,
  DWORD nNumberOfBytesToRead,
  LPDWORD lpNumberOfBytesRead,
  LPOVERLAPPED lpOverlapped
);

However, there are some difference between calling ReadFile for a disk file and for a mailslot stream. If hFile is a handle for the a mailslot, if the param of "nNumberOfBytesToRead" is less than the total message size (you can retrieve it from GetMailslotInfo()), nothing will be read and *lpNumberOfBytesRead will be 0.

This situation raise a problem: if *lpNumberOfBytesRead is less than nNumberOfBytesToRead, what can we do except return an error? As you know, in file stream, you still get something and *lpNumberOfBytesRead will not be 0, so you can continue reading the handle in a loop until all data are read. In mailslot stream, if you do so, in the next loop you still get 0 in *lpNumberOfBytesRead.

Any suggestion for handling this situation?

Thanks



Relevant Pages

  • A question on reading mailslot
    ... LPVOID lpBuffer, ... DWORD nNumberOfBytesToRead, ... LPDWORD lpNumberOfBytesRead, ... Any suggestion for handling this situation. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: dll import problem
    ... // invalid parameter ... LPVOID lpBuffer, ... DWORD nNumberOfBytesToRead, ... LPDWORD lpNumberOfBytesRead, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: how to pass a byte array from managed code ?
    ... > public static extern int ReadFile( ... > LPVOID lpBuffer, ... > DWORD nNumberOfBytesToRead, ... > LPDWORD lpNumberOfBytesRead, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: newbie: I/O with nasm
    ... BOOL ReadFile( ... DWORD nNumberOfBytesToRead, // number of bytes to read ... LPDWORD lpNumberOfBytesRead, ... I don't know what "overlapped buffer" means. ...
    (alt.lang.asm)