使用MFC常规型动态链接库 1、将生成的动态链接库文件(ReguDll.dll)和库文件(ReguDll.lib)拷贝到要调用的工程DllTest的目录下,再将(ReguDll.lib)文件加入到调用工程DllTest中. 2、在调用工程TestDlg.h中加入如下代码,声明动态链接库函数: #define DllImport _declspec(dllimport) extern "C" DllImport float MyFunction(float f1,float f2); 3、在DllTestDlg.cpp中的OnButton1()函数中加入如下代码,直接调用动态链接库函数: float x1,x2,sum; x1 = 12; x2 = 102; sum = MyFunction(x1,x2); CString str; str.Format("The sum of %f and %f is %f",x1,x2,sum); MessageBox(str);
注:源代码下载 
|