BackupWrite sets lpContext to 0xFFFF.... when called with nNumberOfBytesToWrite=0 in versions after 2022
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