±ÏÒµÂÛÎÄ - VC++»·¾³ÏµĶ¯Ì¬Á´½Ó¿âµÄ¿ª·¢ÓëÓ¦ÓÃ

VC++»·¾³Ï¶¯Ì¬Á´½Ó¿âµÄ¿ª·¢¼°Ó¦ÓÃ

²¢Ìí¼ÓÒÔÏ´úÂ룺

void CDllDialog::OnButton1() { } // TODO: Add your control notification handler code here MessageBox(\ \ÔÚRegularDll.cpp µÄ×îºó£¬Ìí¼ÓMFC¹æÔòDLL½Ó¿Úº¯Êý¡£

extern \{ AFX_MANAGE_STATE(AfxGetStaticModuleState()) ; }

CDllDialog dllDialog; dllDialog.DoModal();

ͼ 3-3-6 Ìí¼ÓMFC¹æÔòDLL½Ó¿Úº¯Êý

ÔÚRegularDll.cpp µÄÇ°Ã棬Ìí¼Ó #include \

17

VC++»·¾³Ï¶¯Ì¬Á´½Ó¿âµÄ¿ª·¢¼°Ó¦ÓÃ

ͼ 3-3-7 Ìí¼ÓMFC¹æÔòDLL½Ó¿Úº¯Êý

Íê³ÉÉÏÊö²½Öèºó£¬¾Í¿ÉÒÔ±àÒë²¢Éú³ÉDllÎļþÁË¡£

ͼ 3-3-8 Ìí¼ÓMFC¹æÔòDLL½Ó¿Úº¯Êý

3.4. MFC¹æÔòDLLµÄµ÷ÓÃ

£¨1£©Ê×ÏÈ£¬´´½¨Ò»¸ö»ùÓÚMFCµÄµ¥ÎĵµÓ¦ÓóÌÐò¡°CallRegDll¡±¡£

18

VC++»·¾³Ï¶¯Ì¬Á´½Ó¿âµÄ¿ª·¢¼°Ó¦ÓÃ

ͼ 3-4-1 ´´½¨MFCµÄµ¥ÎĵµÓ¦ÓóÌÐòCallRegDll

£¨2£©Ìí¼ÓÒ»¸ö²Ëµ¥Ïî¡°CallRegDll¡±¡£

ͼ 3-4-2 Ìí¼ÓÒ»¸ö²Ëµ¥Ïî

£¨3£©ÔÚÊÓÀà¶Ô¸Ã²Ëµ¥ÏîÌí¼ÓÏûÏ¢ÏìÓ¦º¯Êý£¬º¯Êý´úÂëÈçÏ£º void CCallRegDllView::OnRegdll() {

19

VC++»·¾³Ï¶¯Ì¬Á´½Ó¿âµÄ¿ª·¢¼°Ó¦ÓÃ

// TODO: Add your command handler code here typedef void (*lpFun)(void);

HINSTANCE hDll=NULL; //DLL¾ä±ú hDll = LoadLibrary(\

if(hDll!=NULL)

{ lpFun pShowDlg = (lpFun)GetProcAddress(hDll,\

if ( pShowDlg!=NULL)

{ pShowDlg(); } else {

MessageBox(\Öк¯ÊýÑ°ÕÒʧ°Ü\ }

} } else { }

MessageBox(\ûÓÐÕÒµ½ÏàÓ¦µÄdll \

£¨4£©±àÒë²¢ÔËÐгÌÐò¡£µã»÷²Ëµ¥Ï»áµ¯³öÈçϽçÃ棺

20

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)