声明:大部分代码使用的是微软源码,请查看相关 API
一、新建 DLL 项目
1.选择 Win32 Project,名字 MathFuncsDll
2.Next ->Application type: DLL->Finish
3.添加 MathFuncsDLL.h
// MathFuncsDll.h
#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport)
#else
#define MATHFUNCSDLL_API __declspec(dllimport)
#endif
namespace MathFuncs {
// This class is exported from the MathFuncsDll.dll
class MyMathFuncs {
public:
// Returns a + b
static MATHFUNCSDLL_API double Add(double a, double b);
// Returns a - b
static MATHFUNCSDLL_API double Subtract(double a, double b);
// Returns a * b
static MATHFUNCSDLL_API double Multiply(double a, double b);
// Returns a / b
// Throws const std::invalid_argument& if b is 0
static MATHFUNCSDLL_API double Divide(double a, double b);
};
}

本文介绍了如何创建及在控制台应用中使用MFC DLL。首先创建了一个名为MathFuncsDll的DLL项目,然后创建Win32 Console Application项目MyExecRefsDll。在APP中使用DLL有两种方式:一是通过解决方案添加DLL项目引用;二是直接复制DLL及其库文件到APP项目,并链接到额外依赖项。
最低0.47元/天 解锁文章
1575

被折叠的 条评论
为什么被折叠?



