C++ DLL 模板

C++ DLL 模板

1、使用VS2005创建Win32 DLL项目,选择空项目,然后加入CppDll.h和CppDll.cpp文件。

2、修改CppDll.h和CppDll.cpp文件使之成为需要的内容。

3、编译生成CppDll.dll。

下面是模板文件:

// // CppDll.h // by cheungmine // C++ DLL 模板 // /*** 使用CPPDLL: #include "../CppDll.h" #ifdef _DEBUG # pragma comment(lib, "F:/del/CppDll/Debug/CppDlld.lib") #else # pragma comment(lib, "F:/del/CppDll/Release/CppDll.lib") #endif ***/ #ifndef _CPPDLL_H__ #define _CPPDLL_H__ //#include <windows.h> //#include <math.h> //#include <assert.h> //#include <memory.h> //#include <malloc.h> // 下列 ifdef 块是创建使从 DLL 导出更简单的宏的标准方法。 // 此 DLL 中的所有文件都是用命令行上定义的 CPPDLL_EXPORTS 符号编译的。 // 在使用此 DLL 的任何其他项目上不应定义此符号。 // 这样,源文件中包含此文件的任何其他项目都会将 CPPDLL_API 函数视为是从此 DLL 导入的, // 而此 DLL 则将用此宏定义的符号视为是被导出的。 #ifdef CPPDLL_EXPORTS #define CPPDLL_API __declspec(dllexport) #else #define CPPDLL_API __declspec(dllimport) #endif #define CPPDLL_VERSION 1.0 // 常量定义 // 名称空间 namespace CppDll { // // 从 CppDll.dll 导出类 // // 导出类: MyStruct struct CPPDLL_API MyStruct { long x; long y; }; // 导出类: MyClass2 class CPPDLL_API MyClass2 { void Clear() { // 实现 }; public: MyClass2(); ~MyClass2(); }; // 导出共享变量 extern CPPDLL_API int g_nVar; // // 导出方法 // CPPDLL_API double Method(const MyStruct *s1, const MyStruct *s2); CPPDLL_API double Method(const MyStruct &s1, const MyStruct &s2); }; // End of namespace CppDll #endif // _CPPDLL_H__

// // CppDll.cpp // by cheungmine // #include "CppDll.h" // 包含其他必要文件 // #include <vector> using namespace CppDll; /// // struct MyStruct /// // class MyClass2 MyClass2::MyClass2() { } MyClass2::~MyClass2() { } /// // 导出变量 CPPDLL_API int g_nVar = 0; /// // 导出方法 CPPDLL_API double CppDll::Method(const MyStruct *s1, const MyStruct *s2) { return 0; } CPPDLL_API double CppDll::Method(const MyStruct &s1, const MyStruct &s2) { return 0; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值