create dll and use it,only use very little thing!
!!!!!!!
1:use:
//func code.
void CAboutDlg::OnTestUseDll()
{
typedef void (WINAPI * func)();
HINSTANCE hmod;
hmod = ::LoadLibrary ("firstDLL.dll");
if(hmod==NULL)
{
AfxMessageBox("Fail");
}
func lpproc;
lpproc = (func)GetProcAddress (hmod,"Show");
if(lpproc!=(func)NULL)
(*lpproc)();
FreeLibrary(hmod);
}
!!!!!!!!!!
//2:sorce code,only add a dlg and in global add a declearion of func and implemention it.!
/////////////////////////////////////////////////////////////////////////////
// The one and only CFirstDLLApp object
CFirstDLLApp theApp;
//give the func that will can be used.
extern "C" __declspec(dllexport) void Show()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
TestDlg test;
test.DoModal ();
}
//and sorce dlg src
// TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "firstDLL.h"
#include "TestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// TestDlg dialog
TestDlg::TestDlg(CWnd* pParent /*=NULL*/)
: CDialog(TestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(TestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void TestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(TestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(TestDlg, CDialog)
//{{AFX_MSG_MAP(TestDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// TestDlg message handlers
void TestDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void TestDlg::OnOK()
{
AfxMessageBox(" in dll 's dlg");
CDialog::OnOK();
}
浙公网安备 33010602011771号