MFC DLL interface creation and invocation

One: Create a DLL link library directly using the MFC DLL creation wizard

There are two ways to call DLL: 1. Implicit call; 2. Explicit call;

Here I use the implicit call. 

The method of implicit calling is very simple, as long as the .dll, .lib, .h files in the generated DLL are placed under the project where the DLL is to be called, and then added to the project.

 

About the writing of the DLL header file: a global extension of the function outside the class, complete with extern "C"

extern "C"{
double addMy(double &m_editSummand, double &m_editAddend);
double ridMy(double &m_editSummand, double &m_editAddend);
double decMy(double &m_editSummand, double &m_editAddend);
double divMy(double &m_editSummand, double &m_editAddend);
}

Then declare the function name and method to be exported in the .def file.

 

When calling in MFC, include the header file of the DLL.

Then you can use the functions of the DLL link library.

E.g:

void CMFCApplication1Dlg::OnClickedAddButton()
{
// TODO: add control notification handler code here

AFX_MANAGE_STATE(AfxGetStaticModuleState()); //Add this function when making a call.
UpdateData(TRUE);
m_editSum = addMy(m_editSummand, m_editAddend);
UpdateData(false);
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324732566&siteId=291194637