使用动态链接库:
1、选择菜单“文件”——“新建”——“工程”——“MFC AppWizard[exe] ”建立一个单窗口程序(命名为“usedll”)
2、为CMyView添加OnLButtonDown处理,添加以下代码:
void CUsedllView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
typedef void(*Ellipse)(CClientDC *pDC,int,int,int,int);
typedef void(*Rectangle)(CClientDC *pDC,int,int,int,int);
Ellipse pEllipse;
Rectangle pRectangle;
HINSTANCE hInstance=LoadLibrary("D:\\c++\\mydll\\Debug\\mydll.dll");
PROC fn1=GetProcAddress(hInstance,"DrawEllipse");
PROC fn2=GetProcAddress(hInstance,"DrawRectangle");
pEllipse=(Ellipse)fn1;
pRectangle=(Rectangle)fn2;
(*pEllipse)(&dc,10,10,100,100);
(*pRectangle)(&dc,100,100,150,150);
CView::OnLButtonDown(nFlags, point);
}
3、编译运行。
评论