Am Dienstag, 24. Februar 2015 schrieb Nikolay Sivov:
On 23.02.2015 15:42, Joachim Priesner wrote:
- if (IS_INTRESOURCE(text))
- {
SetLastError(S_OK);
LoadStringW(instance, LOWORD(text), (LPWSTR)result, 0);
return HRESULT_FROM_WIN32(GetLastError());
- }
You don't need SetLastError(), especially not with HRESULT value. And GetLastError() should only be used when LoadStringW() fails.
Thanks for the feedback, again. The rationale behind SetLastError is that the following three cases can occur: 1) LoadStringW succeeds, string length > 0 => return value > 0 2) LoadStringW succeeds, string length == 0 => return value 0 3) LoadStringW fails => return value 0, error code available via GetLastError.
Because LastError is not modified in case 2), I have to set it to S_OK beforehand in order to distinguish between 2) and 3). Does that make sense?