Hi Everyone,
I have a DLL (native Windows, 32 bit, no COM) which I used to call from a managed C++ wrapper using LoadLibrary and GetProcAddress statements. All went fine, the DLL got loaded, I was able to retrieve the entrypoints and call all the required methods using explicit marshalling. This is on a 32 bit environment, no 64 bits are envolved.
For reasons beyond my control I am forced to rewrite this mechanism using C#, so I created the same (wrapper) classes in C# and created DllImport-attributed signatures for all my DLL functions. However, when I call the first method, I am getting an BadImageFormatException, no matter what function I call. I even declared a non-existing function, but the result was the same exception.
Googling on this topic provides me a lot of 32 vs 64 bit issues, but since my environment is completely 32 bit this solves nothing for me. The only thing that worries me, is when I inspect the DLL using the dependency walker (depends.exe) it shows the following message: "Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.". The IEFRAME.DLL is marked red, but using the LoadLibrary statements I was able to load the DLL.
The declaring statement is:
[DllImport(@"retrievalNLE.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern void SetWebsearchNLETraceLevel(Int32 level);
(but I have also tested with the options CharSet and SetLastError omitted, as well as with every calling convention )
The result is:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
The native Windows LastError is 2.
The file and all dependencies are located in the c:\windows\system32 directory.
Any suggestions on how to call such a DLL from C# are greatly appreciated.
Kind regards,
Martin de Jong
The Netherlands