-2

I am trying to use the following code:

LoadLibraryExA(filename.c_str(), NULL, DONT_RESOLVE_DLL_REFERENCES);

To load a C++\CLR dll from a native assembly. The HMODULE returned is NULL and the GetLastError returns - 193 which means is not a valid win32 application

How can I load the library correctly? What am I doing wrong? Thank you! Ron

Ron Gross
  • 1,474
  • 5
  • 19
  • 34
  • What do you want to do with the DLL once you've loaded it? You are aware that you cannot treat it as an unmanaged DLL? – David Heffernan Jul 22 '14 at 11:24
  • What do you mean by 'treating as unmanaged DLL'. The dll have a singleton class that I want to use (it is declared without 'ref', so as I know - it is native.. ?) – Ron Gross Jul 22 '14 at 11:30

1 Answers1

0

If this is a mixed mode DLL as your comments indicate, then the usual explanation for ERROR_BAD_EXE_FORMAT is that the bitness of the host process does not match the bitness of the DLL. You are trying to load a 32 bit DLL into a 64 bit process, or vice versa.

If you have matching bitness then the most likely explanation is that the DLL is a managed DLL rather than a mixed mode DLL.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490