0
votes

When I try to load a DLL using LoadLibrary, the handle is not null but the GetLastError is returning 14007. Any ideas?

MSDN says:

ERROR_SXS_KEY_NOT_FOUND
14007 (0x36B7)
The requested lookup key was not found in any active activation context

HMODULE handle = LoadLibrary("mydll.dll"); r = GetLastError(); if(!handle) return 0;

1

1 Answers

-1
votes

The error code is not always reset on success.

First and foremost, to find out whether a function call succeeded, you follow the semantics noted in the documentation. In this case, whether LoadLibrary returns a valid handle.

You've indicated that it does, so the result of GetLastError is not relevant. It could be the result from some previous call that failed.

From the GetLastError documentation:

The return value is the calling thread's last-error code.

The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not.

I can't see anything in the LoadLibrary documentation suggesting that the error code is set to 0 on success, meaning it's meaningless in your case.