C++ DLL 模板

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

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

3、编译生成CppDll.dll。

下面是模板文件:

  1. //
  2. // CppDll.h
  3. // by cheungmine
  4. // C++ DLL 模板
  5. //
  6. /*** 使用CPPDLL:
  7. #include "../CppDll.h"
  8. #ifdef _DEBUG
  9. #  pragma comment(lib, "F:/del/CppDll/Debug/CppDlld.lib")
  10. #else
  11. #  pragma comment(lib, "F:/del/CppDll/Release/CppDll.lib")
  12. #endif
  13. ***/
  14. #ifndef _CPPDLL_H__
  15. #define _CPPDLL_H__
  16. //#include <windows.h>
  17. //#include <math.h>
  18. //#include <assert.h>
  19. //#include <memory.h>
  20. //#include <malloc.h>
  21. // 下列 ifdef 块是创建使从 DLL 导出更简单的宏的标准方法。
  22. // 此 DLL 中的所有文件都是用命令行上定义的 CPPDLL_EXPORTS 符号编译的。
  23. // 在使用此 DLL 的任何其他项目上不应定义此符号。
  24. // 这样,源文件中包含此文件的任何其他项目都会将 CPPDLL_API 函数视为是从此 DLL 导入的,
  25. // 而此 DLL 则将用此宏定义的符号视为是被导出的。
  26. #ifdef CPPDLL_EXPORTS
  27. #define CPPDLL_API __declspec(dllexport)
  28. #else
  29. #define CPPDLL_API __declspec(dllimport)
  30. #endif
  31. #define     CPPDLL_VERSION   1.0            // 常量定义
  32. // 名称空间
  33. namespace CppDll
  34. {
  35. //
  36. // 从 CppDll.dll 导出类
  37. //
  38. // 导出类: MyStruct
  39. struct CPPDLL_API MyStruct
  40. {
  41. long    x;
  42. long    y;
  43. };
  44. // 导出类: MyClass2
  45. class CPPDLL_API MyClass2
  46. {
  47. void Clear()
  48. {
  49. // 实现
  50. };
  51. public:
  52. MyClass2();
  53. ~MyClass2();
  54. };
  55. // 导出共享变量
  56. extern CPPDLL_API int g_nVar;
  57. //
  58. // 导出方法
  59. //
  60. CPPDLL_API double Method(const MyStruct *s1, const MyStruct *s2);
  61. CPPDLL_API double Method(const MyStruct &s1, const MyStruct &s2);
  62. };   // End of namespace CppDll
  63. #endif  // _CPPDLL_H__

//
// 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__

  1. //
  2. // CppDll.cpp
  3. // by cheungmine
  4. //
  5. #include "CppDll.h"
  6. // 包含其他必要文件
  7. // #include <vector>
  8. using namespace CppDll;
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // struct MyStruct
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // class MyClass2
  13. MyClass2::MyClass2()
  14. {
  15. }
  16. MyClass2::~MyClass2()
  17. {
  18. }
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // 导出变量
  21. CPPDLL_API int g_nVar = 0;
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // 导出方法
  24. CPPDLL_API double CppDll::Method(const MyStruct *s1, const MyStruct *s2)
  25. {
  26. return 0;
  27. }
  28. CPPDLL_API double CppDll::Method(const MyStruct &s1, const MyStruct &s2)
  29. {
  30. return 0;
  31. }

//
// 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;
}

C++ DLL 模板 .的更多相关文章

  1. VS2005环境下的DLL应用

    VS2005环境下的DLL应用 作者:一点一滴的Beer http://beer.cnblogs.com/ 以前写过一篇题为<VC++的DLL应用(含Demo演示)>的文章,当时是刚开始接 ...

  2. 如何用AU3调用自己用VC++写的dll函数

    这问题困扰我一个上午了,终于找到原因了,不敢藏私,和大家分享一下. 大家都知道,AU3下调用dll文件里的函数是很方便的,只要一个dllcall语句就可以了. 比如下面这个: $result = Dl ...

  3. Coablt strike官方教程中文译版本

    安装和设置 系统要求 Cobalt Strike的最低系统要求 2 GHz +以上的cpu 2 GB RAM 500MB +可用空间 在Amazon的EC2上,至少使用较高核数的CPU(c1.medi ...

  4. MFC模块状态(一)

    先看一个例子: 1.创建一个动态链接到MFC DLL的规则DLL,其内部包含一个对话框资源.指定该对话框ID如下:              #define IDD_DLL_DIALOG  2000 ...

  5. Coablt strike官方教程中文版

    安装和设置 系统要求 Cobalt Strike的最低系统要求 2 GHz +以上的cpu 2 GB RAM 500MB +可用空间 在Amazon的EC2上,至少使用较高核数的CPU(c1.medi ...

  6. T4 模板自动生成带注释的实体类文件 - 只需要一个 SqlSugar.dll

    生成实体就是这么简单,只要建一个T4文件和 文件夹里面放一个DLL. 使用T4模板教程 步骤1 创建T4模板 ,一定要自已新建,把T4代码复制进去,好多人因为用我现成的T4报错(原因不明) 点击添加文 ...

  7. VS编译器从DLL导出模板类

    DLL与模板 http://msdn.microsoft.com/en-us/library/twa2aw10.aspx http://www.codesynthesis.com/~boris/blo ...

  8. [百度空间] [原]DLL导出实例化的模板类

    因为模板是在编译的时候根据模板参数实例化的,实例化之后就像一个普通的类(函数),这样才有对应的二进制代码;否则,没有模板参数,那么编译器就不知道怎么生成代码,所以生成的DLL就没有办法导出模板了.但是 ...

  9. DLL中导出STL模板类的问题

    接上一篇. 上一篇的dll在编译过程中一直有一个警告warning C4251: ‘CLASS_TEST::m_structs’ : class ‘std::vector<_Ty>’ ne ...

随机推荐

  1. Windows下TEX排版论文攻略—CTeX、JabRef使用心得

    笔者刚刚接触到TEX排版,相关知识完全空白,用了两天时间学习并完成了一篇论文的完整排版. 期间遇到不少小问题,着实辛苦,分享至上,现将其解决办法总结归纳,共同学习.     一.工具介绍 TeX是一个 ...

  2. ORA-00001: unique constraint (...) violated解决方案

    ORA-00001: unique constraint (...) violated 的解决方案 今天往Oracle数据库里插入数据一条记录的时候,报错了, 控制台抛出异常:违反唯一性约定, 我以为 ...

  3. (转)ASP.NET并发处理

    对于DB服务器同样也可以调整最大连接数来做优化. 在调整优化好最大连接数之后,就只有软硬件负载均衡了.硬件负载均衡能够直接通过智能交换机实现,处理能力强,而且与系统无关,但是价格贵,配置困难,不能区分 ...

  4. Android Animation学习笔记

    原文地址: http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html 关于动画的实现,Android提供了Animation,在And ...

  5. 慕课网上的Bootstrap学习(二)

    表单 首先<form role="form" class="form-horizontal"></form> ,创建一个水平显示的表单. ...

  6. Java集合源码分析

    Java集合工具包位于Java.util包下,包含了很多常用的数据结构,如数组.链表.栈.队列.集合.哈希表等.学习Java集合框架下大致可以分为如下五个部分:List列表.Set集合.Map映射.迭 ...

  7. 【转】VS2012发布网站详细步骤

    1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: 2.弹出网站发布设置面板,点击<新建..>,创建新的发布配置文件: 输入你自 ...

  8. RequireJS的简单应用

    一.RequireJS的主要作用与优点 主要作用:js模块化.编写复用js代码 优点: 1.防止命名冲突 2.声明不同js文件之间的依赖 3.代码模块化 (1)一个文件一个模块:每个js文件应该只定义 ...

  9. Sublime字体设置

    {"font_face": "Courier New","font_options":["subpixel_antialias&q ...

  10. ES6学习笔记(一)

    1.let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; var b = 1; } a / ...