
How do I export MFC classes from .exe, and call members from a Dll
On Thu, 26 Mar 1998 15:35:28 +0100, "Svend Langen"
Quote:
>Hi there,
>I've been trying to create an MFC extension Dll.
>What I want to do, is to pass a pointer to an MFC derived object (based on
>CDialog)
>to my Dll, and from within the Dll, I want to call the memberfunctions of
>the CDialog class.
>Now, when trying to call the memberfunctions that I've declared, only
>results in an "unresolved external".
>When calling a 'standard' function, like SetWindowText, it works.
>What do I have to do to be able to call 'my own' memberfunctions ??
>BTW the code looks like this:
>Code in .exe:
>class CTestDlg : public CDialog
>{
>...
>void TestFunc(){ AfxMessageBox(_T("Hello"));};
>...
>};
>Code in Dll:
>Exported function in Dll which is called from .exe
>__declspec(dllexport) void DllFunc(CTestDlg* pDlg)
>{
> ...
> pDlg->TestFunc();
> ...
>}
>Any hints greatly appreciated
>Regards
>Svend Langen
Make it virtual.
First put an abstract class in your DLL
// abstractdialog.h
class CAbstractDialog : public CDialog
{
...
public:
virtual void TestFunc()=0 ;
} ;
Then derive from it in your exe
#include "abstractdialog.h"
class CTestDlg : public CAbstractDialog
{
...
public:
virtual void TestFunc() ;
} ;
The DLL only knows about the abstract class, not the derived class, so
change the dll function as follows:
__declspec(dllexport) void DllFunc(CAbstractDialog* pDlg)
{
...
pDlg->TestFunc();
...
}
You could also put "virtual void TestFunc()=0 ;" in a mixin class and
use multiple inheritance or pass a pointer to the function you want to
call to DllFunc().
Don Grasberger
(remove --- from address to e-mail)