PRB: Writing to Resources May Change Last Error

ID: Q137289


The information in this article applies to:


SYMPTOMS

When writing to an application's resources, the value returned by GetLastError may change. This behavior occurs only in Windows 95, not 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.


Keywords          : kbResource kbGrpUser kbWinOS95 kbWinOS98 
Version           : 
Platform          : 
Issue type        : kbprb 

Last Reviewed: March 6, 1999