How do I export MFC classes from .exe, and call members from a Dll 
Author Message
 How do I export MFC classes from .exe, and call members from a Dll

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"));};
...

Quote:
};

Code in Dll:

Exported function in Dll which is called from .exe
__declspec(dllexport) void DllFunc(CTestDlg* pDlg)
{
    ...
    pDlg->TestFunc();
    ...

Quote:
}

Any hints greatly appreciated

Regards

Svend Langen



Mon, 11 Sep 2000 03:00:00 GMT  
 How do I export MFC classes from .exe, and call members from a Dll

The exported function in your DLL should read:

    void __declspec(dllexport) DllFunc(CTestDlg* pDlg)

Also, exporting functions from within an EXE is not common.  Your
MFC-extension DLL should be just that, a DLL.

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




Mon, 11 Sep 2000 03:00:00 GMT  
 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)



Tue, 12 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to export a class from Extension MFC dll to another Extension MFC dll

2. Calling an exported function of a dll which are exported Stdcall calling convention

3. dll export of static const class members

4. Exporting class static data member from DLL( long )

5. Exporting static class member from DLL

6. STL members of a class exported from a DLL

7. Exporting static class member from DLL

8. Exporting static class members from DLL does not work in VC++5.0

9. exporting template class' member functions from dll

10. STL members of a class exported from an NT DLL

11. static variables in exported class having different values between dll and exe

12. static variables in exported class having different values between dll and exe

 

 
Powered by phpBB® Forum Software