problem adding reference

S

shashank.aka.invi

Hi someone plz help me. I have made a dll in VC++ .NET using following
specifications

extern "C"
{
__declspec(dllexport) void Probe_Interfaces_Local()
{
//some code
}
}

i compiled it successfully and add the dll formed to another C# project
directory. The c# code looks like this...

using System;
using System.Runtime.InteropServices;

namespace read
{
class Capture
{
[DllImport("mod2.dll")]
public static extern void Probe_Interfaces_Local();
//some code
}
}
The C# project compiles successfully but when i run it it breaks with
dll exception and says unable to load dll(mod2.dll)
 
G

Gangadhar NPK

I am not very familiar with C# syntax, but have you investigated the
error code ? Also, is it possible that some dependent DLLs of mod2.dll
are not present and the loadlib of the mod2.dll is failing.
just my 2 cents worth..
 
W

Willy Denoyette [MVP]

Hi someone plz help me. I have made a dll in VC++ .NET using following
specifications

extern "C"
{
__declspec(dllexport) void Probe_Interfaces_Local()
{
//some code
}
}

i compiled it successfully and add the dll formed to another C# project
directory. The c# code looks like this...

using System;
using System.Runtime.InteropServices;

namespace read
{
class Capture
{
[DllImport("mod2.dll")]
public static extern void Probe_Interfaces_Local();
//some code
}
}
The C# project compiles successfully but when i run it it breaks with
dll exception and says unable to load dll(mod2.dll)

You must have the DLL in the path of the caller, that is the same directory
or in a directory which is in the path environment.
DllImport uses LoadLibrary to load the DLL, so the same search rules apply
here.

Willy.
 
H

Holger Grund

Willy Denoyette said:
You must have the DLL in the path of the caller, that is the same
directory or in a directory which is in the path environment.
DllImport uses LoadLibrary to load the DLL, so the same search rules apply
here.
And in case the C++ DLL is compiled with /MD(d) and Visual C++
2005 you also need an embedded manifest to bind to the correct CRT
DLL. See the /MANIFESTDEPENDENCY linker switch.

Depends.exe, NT LDR (gflags.exe, "Show Loader Snaps" or _ShowSnaps
variable) are your friends.

-hg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top