Load MFC DLL from C# web service...

G

greg

Hello,

I'm having problems loading my MFC exported function from my C# Web
service. I'm using the DllImport to load the dll and declare the
function like the following:

[DllImport("MyDLL.dll")]
public extern static int MyFunction();

and in the MFC dll it is exported like the following:
__declspec(dllexport) int MyFunction();

When I try to run the web service that makes the call to MyFunction I
get a "Unable to Load DLL" error - what all am I missing? Is their
anything special I need to be doing for loading an MFC Dll from a C#
Web Service?

Thanks,
Greg
(e-mail address removed)
 
N

Nicholas Paldino [.NET/C# MVP]

Greg,

When your ASP.NET page is compiled, it is placed in a temporary space,
and that directory the assembly is in is used as the search path for the
call to LoadLibrary (which the P/Invoke layer is using to load the unmanaged
DLL).

In order to get around this, you have to place MyDLL.dll in a directory
that LoadLibrary can find it in (see the documentation for details) which is
not based on the relative path of your compiled assembly, or you have to
place the full path name of the dll in the DllImport attribute.
 

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