Accessing an MFC dll

S

Sinex

Hi,
I have this MFC dll which I want to reuse in my .NET application If it was
a COM dll then just adding a reference would have created the .net wrapper
for me and the world would have been a simple place :) But its not so with
the MFC dl...so what should I do to reuse this guy?

Sinex
 
M

Matt

Sinex said:
Hi,
I have this MFC dll which I want to reuse in my .NET application If it was
a COM dll then just adding a reference would have created the .net wrapper
for me and the world would have been a simple place :) But its not so with
the MFC dl...so what should I do to reuse this guy?

You just import the functions you want. To steal an example from
someone else's code I just saw:

[DllImport("user32")] public static extern int SetWindowPos(int hwnd);

where user32 is the name of the DLL that you want and the rest of it is
the function. Of course, you have to stick with C# type conventions.

Matt
 
W

Wessel Troost

I have this MFC dll which I want to reuse in my .NET application If it
was
a COM dll then just adding a reference would have created the .net
wrapper
for me and the world would have been a simple place :) But its not so
with
the MFC dl...so what should I do to reuse this guy?
If it's a "plain DLL" that uses MFC internally, you can use P/Invoke to
call functions in the DLL. An example:

using namespace System::Runtime::InteropServices;

extern "C" {
[DllImport("YourMfcDll")]
double Add(double num1, double num2);
}

But if your DLL exposes MFC classes, in the way where you can pass a
CString to another DLL for example, I am afraid it can be consumed only by
another MFC application.

Greetings,
Wessel
 

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