mhelinx09
asked on
Calling a function in the Main application from a DLL
Hi,
There is this application that has a scenario like this:
Main Application:
SDI with CListView
BaseDialog
DLL:
MFC Extension DLL
Derived Dialog (base from BaseDialog)
I'm using dynamic loading to create an instance of the DeriveDialog and pass it to the BaseDialog so that I can manipulate the functions of DeriveDialog in the Main Application.
But this is the problem, how about if there is an event in the DeriveDialog that it needs to call a function in the Main Application?
I tried to pass a pointer of the main application to function inside the DerivedDialog (implemented also as virtual in the BaseDialog) but I'm having a link error when I call the function inside the main Application
Example:
Main Application: (Implemented as SDI with CListView)
TestView::Hello() - function
BaseDialog:
virtual void Test(TestView* m_pView)
DLL: (Implemented as MFC Extension DLL)
DerivedDialog:
void Test(TestView* m_pView)
{
m_pView->Hello() - Linking error
}
I hope someone can help on my problem.
Mhelinx
There is this application that has a scenario like this:
Main Application:
SDI with CListView
BaseDialog
DLL:
MFC Extension DLL
Derived Dialog (base from BaseDialog)
I'm using dynamic loading to create an instance of the DeriveDialog and pass it to the BaseDialog so that I can manipulate the functions of DeriveDialog in the Main Application.
But this is the problem, how about if there is an event in the DeriveDialog that it needs to call a function in the Main Application?
I tried to pass a pointer of the main application to function inside the DerivedDialog (implemented also as virtual in the BaseDialog) but I'm having a link error when I call the function inside the main Application
Example:
Main Application: (Implemented as SDI with CListView)
TestView::Hello() - function
BaseDialog:
virtual void Test(TestView* m_pView)
DLL: (Implemented as MFC Extension DLL)
DerivedDialog:
void Test(TestView* m_pView)
{
m_pView->Hello() - Linking error
}
I hope someone can help on my problem.
Mhelinx
ASKER
Rosmon,
You're my savior!!!
Can you elaborate it? I checked MSDN but they have a small definition about it.
Thanks!!!
Mhelinx
You're my savior!!!
Can you elaborate it? I checked MSDN but they have a small definition about it.
Thanks!!!
Mhelinx
Main Application: (Implemented as SDI with CListView)
in header
afx_msg long Hello();
#define WM_USER_HELLO WM_USER+100
BEGIN_MESSAGE_MAP()
ON_MESSAGE(WM_USER_HELLO, Hello)
END_MESSAGE_MAP()
TestView::Hello() - function
BaseDialog:
virtual void Test(HWND hWnd)
DLL: (Implemented as MFC Extension DLL)
DerivedDialog:
#define WM_USER_HELLO WM_USER+100
void Test(HWND hWnd)
{
::PostMessage(hWnd, WM_USER_HELLO, 0, 0);
}
Call this dll function from view like this
*pfnTest(this->m_hWnd);
here this->m_hWnd is the window handle of the View class
Good Luck
in header
afx_msg long Hello();
#define WM_USER_HELLO WM_USER+100
BEGIN_MESSAGE_MAP()
ON_MESSAGE(WM_USER_HELLO, Hello)
END_MESSAGE_MAP()
TestView::Hello() - function
BaseDialog:
virtual void Test(HWND hWnd)
DLL: (Implemented as MFC Extension DLL)
DerivedDialog:
#define WM_USER_HELLO WM_USER+100
void Test(HWND hWnd)
{
::PostMessage(hWnd, WM_USER_HELLO, 0, 0);
}
Call this dll function from view like this
*pfnTest(this->m_hWnd);
here this->m_hWnd is the window handle of the View class
Good Luck
ASKER
Many thanks rosmon,
How about if you have parameter on the function (e. g. CString)
TestView::Hello(CString sInput) - function
Thanks!
Mhelinx
How about if you have parameter on the function (e. g. CString)
TestView::Hello(CString sInput) - function
Thanks!
Mhelinx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot savior.
This what I did.
Base Dialog:
GetHandle(HWND hWnd)
protected:
HWND m_hWndHandle;
Main Application:
GetHandle(this->hWnd);
DO you think this is safe?
Thanks again.
Mhelinx
This what I did.
Base Dialog:
GetHandle(HWND hWnd)
protected:
HWND m_hWndHandle;
Main Application:
GetHandle(this->hWnd);
DO you think this is safe?
Thanks again.
Mhelinx
Yes, its fine...
Pass the view handle (not pointer) to the dll function
Good luck