BackupWrite sets lpContext to 0xFFFF.... when called with nNumberOfBytesToWrite=0 in versions after 2022

Anatol Piotrowski 0 Reputation points
2024-06-11T15:26:21.3566667+00:00

Seems like behavior of BackupWrite (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-backupwrite) changed after Server 2022.
In versions windows 10.0.20348.2461 and before, BackupWrite when called with nNumberOfBytesToWrite=0 does not change lpContext, it returns 1 and GetLastError() returns 0

However in newer windows versions, when BackupWrite is called with nNumberOfBytesToWrite=0

  • After BackupWrite call, lpContext is changed to 0xFFFFFFF...
  • BackupWrite still returns 1 and GetLastError() returns 0
  • This affects WinPE (versions 10.0.22621.1, 10.0.26100.1) as well as Server 2025 preview (version 10.0.26100.560)

This is definitely a change in behavior. I do not see it documented.
Is this intended behavior?

Since file has multiple streams, when code tries to write next stream with BackupWrite, it fails due to invalid lpContext. No error is returned, GetLastError() is 0, but lpNumberOfBytesWritten is 0.

I can reproduce it every time when using BackupWrite to restore data of c:\ProgramData\Microsoft\Network\Downloader\qmgr.db

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,651 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.