开发者

PInvoke c++ dll from c# - An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

开发者 https://www.devze.com 2023-03-01 08:40 出处:网络
Trying to access an old c++ dll from c# using Dll Import. Been searching around the net for aprox 4 days now without success.

Trying to access an old c++ dll from c# using Dll Import. Been searching around the net for aprox 4 days now without success.

I'm trying to use the c++ dll from an asp.net mvc 3 website .net 4.

I've changed platform target to x86. I've set "Enable 32 bit application" to true on the application pool in iis.

Using Windows Server 2008 R2 with iis 7.5

Is there some way to debug this or get more info about what might be wrong?

The link ASP.NET P/Invoke "An attempt was made to load a program with an incorrect format" states that:

"To use the 32 bit dll, your web application has to run in 32 bit mode, which is done by switching IIS to run in 32 bit mode" and gives a link about how you can change this, however this seems only to concern IIS 6 and asp.net 2

Thanks in advance! Best Regards

Edit 1: Would an erroneous declaration of the c++ method calls in c# result in this er开发者_Python百科ror? Reading the error one could guess that calling a function with 3 params that should receive 4 would result in this error.


Well to answer your last question:

Would an erroneous declaration of the C++ method calls in c# result in this error?

No, I don't believe that it would - erroneous declaration of the C++ method could result in a number of things happening ranging from the function executing correctly to an interop exception being thrown, however I don't believe that this exception would be thrown - this is specific to a problem loading the dll.

You should check to make sure that the process attempting to load this dll is actually a 32-bit process by somehow obtaining the process ID (e.g. by catching and logging the exception), and then checking in task manager. If the process is actually a 64-bit process then you may have incorrectly configured something.

You should also check to ensure that the dll you are attempting to load (and all its dependencies) are in fact 32-bit - I believe that you will experience a similar issue if you attempt to load a 64-bit dll into a 32-bit process. You should be able to use Dependency walker (an all-round very useful tool) to check this.

0

精彩评论

暂无评论...
验证码 换一张
取 消