Microsoft KB Archive/137289

{|
 * width="100%"|

PRB: Writing to Resources May Change Last Error

 * }

Q137289

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), used with:
 * Microsoft Windows 95
 * Microsoft Windows 98
 * the operating system: Microsoft Windows 2000

-

SYMPTOMS
When writing to an application's resources, the value returned by GetLastError may change. This behavior occurs in Windows 95, Windows 98 and Windows 2000, but not in Windows NT.

CAUSE
When an application writes to its own resources, a page fault occurs, which is handled internally by the kernel. The handling of this page fault may change the value returned by GetLastError.

RESOLUTION
To avoid this problem:


 * 1) Don't write to your own resources. The pointer returned by LockResource should be treated as read-only. This was always the intention, however, writing to your own resources happens to work on Windows NT.
 * 2) If you really need to write to your own resource, do not rely on the last error being preserved. If the value returned by GetLastError is important to you, call GetLastError before writing to your own resource. Then call SetLastError to restore the value after you are finished.

STATUS
This behavior is by design.

MORE INFORMATION
It is legitimate for an API to change the last error even when it is successful.

Additional query words:

Keywords : kbOSWin2000 kbResource kbSDKWin32 kbGrpDSUser kbOSWin95 kbOSWin98

Issue type : kbprb

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch