WriteFileEx and ERROR_MORE_DATA

Pierre Chatelier 81 Reputation points
2022-02-08T22:04:30.06+00:00

The documentation of WriteFileEx is unclear about ERROR_MORE_DATA.
It just says that it can happen

For example, a buffer overflow when calling WriteFileEx will return TRUE, but GetLastError will report the overflow with ERROR_MORE_DATA. If the function call is successful and there are no warning conditions, GetLastError will return ERROR_SUCCESS

But the doc should explain :
-what kind of "buffer overflow" is this ?
-what does that mean when it happens, especially for a file handle ? Is it something like "not enough bytes were written" (I assume it could be, for a file, that no more space is available, but isn't it another error ?)
-if such an error occurs, will the completion routine be called ? And is it possible that some bytes have been successfully written ? (the number of bytes written as reported by the completion routine being less than the expected count)
-assuming that I can retry sending the "missing" bytes, should I do that by issuing a new WriteFileEx() without the bytes already sent ?
-in such a case can it be/should it be done from the completion routine, or from the caller of WriteFileEx() ? In both cases, the problem is that subsequent calls to WriteFileEx () might have been already queued for other handles, so it seems very difficult to handle properly

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,441 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 15,601 Reputation points Microsoft Vendor
    2022-02-09T08:48:02.807+00:00

    Hello,
    Welcome to Microsoft Q&A!

    Thank you for pointing out the lack of detail in the document. Our team will improve it.

    "what kind of "buffer overflow" is this ?"
    "what does that mean when it happens, especially for a file handle ? "
    "Is it something like "not enough bytes were written" (I assume it could be, for a file, that no more space is available, but isn't it another error ?)"

    Buffer overflow, too much information is being passed into a container that does not have enough space, This container can be a file, file stream, physical disk, volume, console buffer, tape drive, socket, communications resource, mailslot, or pipe.

    "if such an error occurs, will the completion routine be called ? "

    In my test, if buffer overflow occurs, completion routine be called successfully.

    "And is it possible that some bytes have been successfully written ? (the number of bytes written as reported by the completion routine being less than the expected count)"

    The target container is filled and excess data overflows.

    "assuming that I can retry sending the "missing" bytes, should I do that by issuing a new WriteFileEx() without the bytes already sent ?"

    If you want send the "missing" bytes, the first thing is to make the container bigger. WriteFileEx() cannot currently add data to the end of a file.

    "in such a case can it be/should it be done from the completion routine, or from the caller of WriteFileEx() ? In both cases, the problem is that subsequent calls to WriteFileEx () might have been already queued for other handles, so it seems very difficult to handle properly"

    Need to use GetLastError in your program to check for errors.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.