www.pudn.com > win32.rar > TestDllNView.cpp
// TestDllNView.cpp : CTestDllNView 类的实现
//
#include "stdafx.h"
#include "TestDllN.h"
#include "TestDllNDoc.h"
#include "TestDllNView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTestDllNView
IMPLEMENT_DYNCREATE(CTestDllNView, CView)
BEGIN_MESSAGE_MAP(CTestDllNView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_COMMAND(ID_TESTDLLN, OnTestdlln)
END_MESSAGE_MAP()
// CTestDllNView 构造/销毁
CTestDllNView::CTestDllNView()
{
// TODO: 在此处添加构造代码
}
CTestDllNView::~CTestDllNView()
{
}
BOOL CTestDllNView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
// 样式
return CView::PreCreateWindow(cs);
}
// CTestDllNView 绘制
void CTestDllNView::OnDraw(CDC* /*pDC*/)
{
CTestDllNDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: 在此处为本机数据添加绘制代码
}
// CTestDllNView 打印
BOOL CTestDllNView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CTestDllNView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印前添加额外的初始化
}
void CTestDllNView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 打印后添加清除过程
}
// CTestDllNView 诊断
#ifdef _DEBUG
void CTestDllNView::AssertValid() const
{
CView::AssertValid();
}
void CTestDllNView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestDllNDoc* CTestDllNView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDllNDoc)));
return (CTestDllNDoc*)m_pDocument;
}
#endif //_DEBUG
// CTestDllNView 消息处理程序
void CTestDllNView::OnTestdlln()
{
// TODO: 在此添加命令处理程序代码
float x1,x2,sum;
x1=10;
x2=100;
typedef float (SUMFUNC)(float,float);
HINSTANCE hInstance;
SUMFUNC* pSum;
//加载DLL
VERIFY(hInstance=LoadLibrary("DllN.dll"));
//获取FindSum函数的地址
VERIFY(pSum=(SUMFUNC *)GetProcAddress(hInstance,"FindSum"));
//计算两数之和
sum=(* pSum)(x1,x2);
//显示结果
CString str;
str.Format("The sum of %f and %f is %f",x1,x2,sum);
MessageBox(str);
//卸载DLL
VERIFY(FreeLibrary(hInstance));
}