Native loading works good. Loading from .net gives error Unable to load DLL 'my.dll': Invalid access to memory location
Asked Answered
A

1

1

I'm trying to use native dll, using DllImport. And I receive such error.

System.DllNotFoundException: Unable to load DLL 'my.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

That dll loads normally when is called from native code (it is used from delphi app). But when I call it from .net code, it gives me exception above.

I've read this link Windows Vista: Unable to load DLL 'x.dll': Invalid access to memory location. (DllNotFoundException), but no solution helps.

DEP, Administration rights are not the case.

P.S. This situation occurs on Windows 2008 server. On Win 2003 Server and XP everything works great.

Athwartships answered 21/3, 2011 at 9:17 Comment(5)
What happens when you load it from your Delphi app on Win2008 server? Is the 2008 server 64 bit? Are you targetting AnyCPU or x86?Halbeib
Everything works fine, when I load it from delphi. No errors.Athwartships
and the questions about 64bit, AnyCPU etc.?Halbeib
2) Server 2008 - 32 bit. 3) x86Athwartships
Assuming the DLL is a Delphi DLL, try emitting some debug information from some of your unit initialization sections to see how far through initialization the DLL gets.Halbeib
A
1

It seems I've found the problem. The problem was in DEP feature. When I switched on DEP for essential programs only, it gave no effect. But when I completely switched off DEP, and rebooted my server, error has gone. The one more thing I've done - installed latest updates for .net 4.0

Athwartships answered 22/3, 2011 at 13:12 Comment(1)
One more thing. The .net application didn't specified that this is DEP Error. I've observed it only when calling this dll from own written test native application. But why delphi native app didn't hve this error - it is still mistery.Athwartships

© 2022 - 2024 — McMap. All rights reserved.