views:

49

answers:

1

I'm having exactly the same problem as the poster in this question. I have a visual studio C# projects from which I'm trying to call a function in another DLL (which is also part of the solution).

The DLL is a C++ one and the exported function I'm trying to call is declared like this in C#:

[DllImport("SomeDLL.dll")]
private extern static IntPtr SomeFunction(IntPtr someVar1, IntPtr someVar2, bool someVar3);

When I try to call the function from C# I see the following on the console output in the debugger:

'MyApp.exe': Loaded 'C:\SomePath\Build\Eddy\Debug\SomeDLL.dll'
'MyApp.exe': Unloaded 'C:\SomePath\Build\Eddy\Debug\SomeDLL.dll'
'MyApp.exe': Loaded 'C:\SomePath\Build\Eddy\Debug\SomeDLL.dll'
'MyApp.exe': Unloaded 'C:\SomePath\Build\Eddy\Debug\SomeDLL.dll'

And I the get the following error dialog:

Unable to load DLL 'SomeDLL.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

The code in question works fine on my colleagues windows XP machine. There's also another C++ DLL in the solution which works fine.

+2  A: 

The problem seems to be that SomeDll.dll cannot be loaded. There are a few different reasons for why this may happen and some of them are:

  1. The dll is 32-bit and you are running a 64-bit process (or the other way around).
  2. SomeDLL.dll has some additional dependencies (other dll:s or COM components) that are not available.

You can run Dependeny Walker: http://www.dependencywalker.com/ on your somedll.dll to see if it is point 2 that is the problem.

Andreas Paulsson
The non working DLL had dependencies to some other DLLs, when I copied these into the working directory of my C# project everything worked fine.
Andreas Brinck