On Wed, Apr 9, 2008 at 10:02 PM, Dmitry Timoshkov &lt;<a href="mailto:dmitry@codeweavers.com">dmitry@codeweavers.com</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&quot;Erich Hoover&quot; &lt;<a href="mailto:ehoover@mines.edu" target="_blank">ehoover@mines.edu</a>&gt; wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+ &nbsp; &nbsp;oldError = GetLastError();<br>
+ &nbsp; &nbsp;/* Read and Write sharing are necessary if a flush is performed on an open file */<br>
+ &nbsp; &nbsp;hFile = CreateFileW(CurProfile-&gt;filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);<br>
 &nbsp; &nbsp; if (hFile == INVALID_HANDLE_VALUE)<br>
 &nbsp; &nbsp; {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; WARN(&quot;could not save profile file %s (error was %d)\n&quot;, debugstr_w(CurProfile-&gt;filename), GetLastError());<br>
 &nbsp; &nbsp; &nbsp; &nbsp; return FALSE;<br>
 &nbsp; &nbsp; }<br>
+ &nbsp; &nbsp;/* The operation has succeed, do not over-write the error code */<br>
+ &nbsp; &nbsp;SetLastError(oldError);<br>
</blockquote>
<br>
It&#39;s been said many times that if you need to save/restore last error value<br>
you are doing something wrong.</blockquote><div><br>Well, I could call NtCreateFile directly so that the error code never gets set in the first place...<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+ &nbsp; &nbsp;/* Get* routines set S_OK on success, Write* routines return last error */<br>
+ &nbsp; &nbsp;SetLastError(S_OK);<br>
</blockquote>
<br>
There is no point in setting or checking last error value on success in vast<br>
majority of cases, do you have an app that depends on this? Besides, S_OK is<br>
an OLE error code and can not be used in kernel.<br>
</blockquote><div><br>This was done to satisfy a problem pointed out in the previous attempt, that patch broke a test in test_profile_sections where it checks that GetPrivateProfileSectionA()&#39;s GetLastError() is S_OK.&nbsp; I figured that the code should be consistent with the (existing) test, if you think it&#39;s more appropriate then both could be changed to ERROR_SUCCESS.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
-- <br><font color="#888888">
Dmitry. <br>
</font></blockquote></div><br>