MFC application calls MFC DLL (with dialog box inside)

Source: Internet
Author: User

1. MFC DLL

(1) Create a project, create an Arbitrary dialog box test program;

(2) Create an # include "ExpertFunc.h"

#pragma once
#include "MakeDLL.h"

There's a problem with this method.
CWnd * InitData (CWnd * pwnd/* Parent window pointer, passed in by the caller, typically the main dialog box */)
{
Afx_manage_state (AfxGetStaticModuleState ());
Makedll * Pdlg = new Makedll;
if (Pdlg->create (Makedll::idd, Cwnd::fromhandle (Pwnd->getsafehwnd ())))
{
Pdlg->setparent (PWND);
Pdlg->showwindow (Sw_show);
return PDLG;
}
return NULL;
}
extern "C" __declspec (dllexport) void Show ()
{
Afx_manage_state (AfxGetStaticModuleState ());
Makedll test;
Test. DoModal ();
}
(3) in. def
; Makemfcdll.def: Declares the module parameters of the DLL.
LIBRARY
Exports
; This can be an explicit export
InitData @1//No
Show @2
2. MFC application (1) Create an MFC application (2) Add a button in the window and double-click the build Event
Button event void Cdlltestdlg::onbnclickedbutton1 ()
{
TODO: Add control notification Handler code here
typedef void (WINAPI * testdll) ();
HINSTANCE Hmod;
Hmod =:: LoadLibrary (_t ("MakeMFCDLL.dll"));
if (Hmod = = NULL)
{
AfxMessageBox (_t ("Fail"));
}
Testdll Lpproc;
Lpproc = (testdll) GetProcAddress (Hmod, "Show");
cwnd* pWnd1 = Cwnd::fromhandle (m_hwnd);
if (lpproc! = (testdll) NULL)
(*lpproc) ();
FreeLibrary (HMOD);


/*hinstance Hmod;
Hmod =:: LoadLibrary (_t ("MakeMFCDLL.dll"));
LPARAM LPARAM = 0;
Load (_t ("MakeMFCDLL.dll"), _t (""), LParam); */

}
Code with the problem
void Cdlltestdlg::load (CString strmodulename, CString strtitle, LPARAM lparam/* = 0*/)
{
Determine if the number of tabs exceeds the set
/*cini INI;
if (M_wndtab.getitemcount () >= (int) ini. GetInt (_t ("System"), _t ("Maxtabs"), 10))
{
_startprompt;
if (startprompt) startprompt (Prompt_type_popup, _t ("Too many tabs, close some tabs before you try to open them. "), 0X0000FF, Prompt_pos_top_center, this, NULL, FALSE);
Return
}*/
cwnd* pWnd1 = Cwnd::fromhandle (m_hwnd);
hmodule hdll = LoadLibrary (strModuleName);
if (hdll)
{
typedef CWnd * (*intidata) (CWnd *);
Intidata InitData = (intidata) GetProcAddress (hDLL, "InitData");
if (InitData)
{
unsigned int uversion = 0;
CWnd * pWnd = InitData (PWND1);
if (pWnd)
{
Pwnd->showwindow (SW_SHOWNORMAL);
Pwnd->updatewindow ();
}
}
}
}
Reference: http://bbs.csdn.net/topics/390948839

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.