Hello, I'm trying to use P/Invoke to get function from MFC Dll.
[DllImport("Obstetrics.dll")]. But I've got an exeption (HANDLE:0x8007007E): Dll couldn't be found. The path is correct (even when I move dll to application's folder this problem happens). DllDependency say anything about errors. Help me please to solve this problem.
AlanPosted Sep 12, 2008, 7:13 AM
The most likely explanation is that the MFC dll depends on another dll which can't be found by DllImport. Have you checked the dll's dependencies with Dependency Walker or dumpbin?
Incidentally, you'll find it's impossible to invoke class member functions in the dll unless there's a static way of obtaining a pointer to the MFC class object concerned. However, invoking a static or global function shouldn't be a problem.
AlanPosted Sep 12, 2008, 10:07 AM
The only other ways are:
1. To try and convert it to a COM dll which can then be used directly from C#.
2. To write a wrapper dll in C++/CLI which can then expose the classes and/or functions you need to managed code. So, the C++/CLI dll would import the MFC dll and then a reference to the former would be added to the C# project. This can only be done in C++/CLI as its the only .NET language which supports mixed mode (managed and unmanaged) applications.
If you only want to use a small part of the MFC dll's functionality, then #2 might be your best bet. Otherwise I'd go for #1.
AlexandrPosted Sep 12, 2008, 8:20 AM
There're a few DLLs which this MFC dll depends on (MFC80.dll, MSVCR80.dll and MSVCP80.dll). When I was trying to test imported functions they all couldn't be found, however they were not "missing DLLs". Is there any other way to use MFC DLLs in .NET applications ?