Вы находитесь на странице: 1из 5

PROJECT NAME : dllformula

In dllformula.cpp

#include "stdafx.h"
#include "dllformula.h"
#include "Math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//

// CDllformulaApp

BEGIN_MESSAGE_MAP(CDllformulaApp, CWinApp)
//{{AFX_MSG_MAP(CDllformulaApp)
// NOTE - the ClassWizard will add and remove mapping macros
here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CDllformulaApp construction

CDllformulaApp::CDllformulaApp()
{ }

// The one and only CDllformulaApp object

CDllformulaApp theApp;

extern "C" _declspec(dllexport)double findsquareroot(double d)


{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(d>0.0)
{
return sqrt(d);
}
AfxMessageBox("NO");
return 0.0;
}

PROJECT NAME : dllapp

In dllimp.h

extern "C" _declspec(dllimport)double findsquareroot(double d);

In dllimp.cpp

#include "stdafx.h"
#include "dllapp.h"
#include "dllimp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// Cdllimp dialog

Cdllimp::Cdllimp(CWnd* pParent /*=NULL*/)


: CDialog(Cdllimp::IDD, pParent)
{
//{{AFX_DATA_INIT(Cdllimp)
m_input = 0.0;
m_output = 0.0;
//}}AFX_DATA_INIT }
void Cdllimp::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cdllimp)
DDX_Text(pDX, IDC_EDIT1, m_input);
DDX_Text(pDX, IDC_EDIT2, m_output);
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(Cdllimp, CDialog)
//{{AFX_MSG_MAP(Cdllimp)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// Cdllimp message handlers

void Cdllimp::OnButton1()
{
UpdateData(true);
m_output=findsquareroot(m_input);
UpdateData(false);
}

In dllappView.cpp

void CDllappView::OnLButtonDown(UINT nFlags, CPoint point)


{
Cdllimp dlg;
dlg.DoModal();
CView::OnLButtonDown(nFlags, point);
}
OUTPUT

Вам также может понравиться