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. iOS开发——打包ipa

    首先,保证设备证书和配置文件的正确,Xcode上登陆好自己公司的账号Apple ID 1.选中运行模拟器的位置为硬件设备 2.点击导航栏上的[Product]——[Archive]后编译后弹出如下界面 ...

  2. CSS常见的浏览器前缀

    为了让浏览器识别某些专属属性,有时候需要在CSS属性前增加浏览器前缀 -ms-:Microsoft IE -moz-:Mozilla Firefox -o-:Opera Opera -webkit-: ...

  3. System.Windows.Forms.Timer反编译学习

    using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...

  4. Tomcat遇到的问题The Tomcat server configuration at ServersTomcat v5.5 Server at localhost-config is missing. Check..

    一.解决方法 删除Servers视图,重新创建一个即可.

  5. 何谓IOC的核心思想

    IOC(Inversion of Control)即控制反转,是在面试或平常交流中经常遇到了词汇:我也曾经仿照Spring,利用JDK的反射和动态代理实现了一个简单的IOC框架,感觉算是知其然也知其所 ...

  6. 在HTML5中怎样实现Canvas阴影效果

    该文章是由e良师益友技术部小陈原创作品,转载是请注明来源,谢谢! 今天我给大家介绍一下在HTML5中怎样实现Canvas阴影效果,我们知道现在HTML5的Canvas阴影也经常使用的,这个就是HTML ...

  7. 【转】JS函数的定义与调用方法

    JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式:先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来 ...

  8. Tomcat & Nginx

    http://cxshun.iteye.com/blog/1535188 反向代理方式实际上就是一台负责转发的代理 服务器,貌似充当了真正服务器的功能,但实际上并不是,代理服务器只是充当了转发的作用, ...

  9. 前端encodeURIComponent 和后端http_build_query配合

    解决特殊字符不能转义 1.  function fixedEncodeURIComponent (str) {  return encodeURIComponent(str).replace(/[!' ...

  10. Pandas之容易让人混淆的行选择和列选择

    在刚学Pandas时,行选择和列选择非常容易混淆,在这里进行一下讨论和归纳 本文的数据来源:https://github.com/fivethirtyeight/data/tree/master/fa ...