The documentation for
InitOnceExecuteOnce
says
If the function fails, the return value is zero. To get extended error information, call GetLastError.
On the other hand, the documentation for the
InitOnceCallback
says
If the function returns FALSE, the block is not marked as initialized and the call to InitOnceExecuteOnce fails. To communicate additional error information, Gall GetLastError. before returning FALSE.
The second paragraph implies that
the
InitOnceExecuteOnce
function
does not itself call
GetLastError
,
because if it did,
then that would wipe out
the value set by the callback.
Is that really the case?
Yes, that's really the case.
The remark in the first paragraph about calling
GetLastError
presupposes
that your callback uses
GetLastError
to report
why it wasn't able to initialize.
I agree, however, that the documentation is misleading here.
But if your callback wants to return status information more complex than a single "success/failed", you are probably better served by the synchronous two-phase initialization pattern, which makes it a lot easier to return more complex information. You can even use it to throw a C++ exception.