views:

31

answers:

2

The LoadLibrary function is returning to me the error code 182. From MSDN:

ERROR_INVALID_ORDINAL: "The operating system cannot run %1"

Does anyone have a better description of what this error is?

A: 

Are you sure that this error is coming from LoadLibrary? Windows DLLs allow you to specify exports by name and ordinal value. That is, each function can be identified by a number. If you call GetProcAddress and specify an invalid ordinal, then you'll get this error.

My best guess is that the DLL that you're loading is calling GetProcAddress in its DllMain and specifying an invalid ordinal. This causes it to fail, and when you call GetLastError, you get ERROR_INVALID_ORDINAL since that's the last error that occurred.

Peter Ruderman
@Peter, I'm pretty sure it's coming from LoadLibrary, as the exports for this library are ok. I'm thinking of static dependencies of this library. Is it possible?
korbes
Whatever the problem, it's certainly caused during initialization of the DLL. Whether that happens in DllMain or during import resolution, I'm not sure. I honestly don't know what error what error it will throw if resolution of a static import in the DLL fails.
Peter Ruderman
A: 

Very obscure error. The term "ordinal" is however strongly associated with a DLL. A DLL contains a list of exported functions as well as a list of imported functions. Other DLLs that it has a dependency on. These exports and imports usually have a name, but that's not required. They always have a number, the number is the "ordinal".

To start diagnosing this, use the SDK's Dumpbin.exe tool. Run this first:

Dumpbin /exports Blah.dll

and look at the list of exports. You should see the ordinal as well as the name. If that all checks out, run

Dumpbin /imports Blah.dll

to get a list of the dependencies. Odds are good that it has a dependency on a function in another DLL by number that this DLL doesn't have. Something like that anyway. You can probably make it less laborious by using the DependencyWalker tool. If the first step fails then something went drastically wrong when the DLL was built. If the second step fails then you're probably looking at some kind of DLL Hell problem.

Hans Passant