On Wed, Apr 9, 2008 at 10:02 PM, Dmitry Timoshkov <dmitry@codeweavers.com> wrote:
"Erich Hoover" <ehoover@mines.edu> wrote:
+ oldError = GetLastError();
+ /* Read and Write sharing are necessary if a flush is performed on an open file */
+ hFile = CreateFileW(CurProfile->filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
WARN("could not save profile file %s (error was %d)\n", debugstr_w(CurProfile->filename), GetLastError());
return FALSE;
}
+ /* The operation has succeed, do not over-write the error code */
+ SetLastError(oldError);
It's been said many times that if you need to save/restore last error value
you are doing something wrong.
+ /* Get* routines set S_OK on success, Write* routines return last error */
+ SetLastError(S_OK);
There is no point in setting or checking last error value on success in vast
majority of cases, do you have an app that depends on this? Besides, S_OK is
an OLE error code and can not be used in kernel.
--
Dmitry.