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://video2.skills-academy.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,493 questions
{count} votes