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.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;
- }
//
// 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 模板 .的更多相关文章
- VS2005环境下的DLL应用
VS2005环境下的DLL应用 作者:一点一滴的Beer http://beer.cnblogs.com/ 以前写过一篇题为<VC++的DLL应用(含Demo演示)>的文章,当时是刚开始接 ...
- 如何用AU3调用自己用VC++写的dll函数
这问题困扰我一个上午了,终于找到原因了,不敢藏私,和大家分享一下. 大家都知道,AU3下调用dll文件里的函数是很方便的,只要一个dllcall语句就可以了. 比如下面这个: $result = Dl ...
- Coablt strike官方教程中文译版本
安装和设置 系统要求 Cobalt Strike的最低系统要求 2 GHz +以上的cpu 2 GB RAM 500MB +可用空间 在Amazon的EC2上,至少使用较高核数的CPU(c1.medi ...
- MFC模块状态(一)
先看一个例子: 1.创建一个动态链接到MFC DLL的规则DLL,其内部包含一个对话框资源.指定该对话框ID如下: #define IDD_DLL_DIALOG 2000 ...
- Coablt strike官方教程中文版
安装和设置 系统要求 Cobalt Strike的最低系统要求 2 GHz +以上的cpu 2 GB RAM 500MB +可用空间 在Amazon的EC2上,至少使用较高核数的CPU(c1.medi ...
- T4 模板自动生成带注释的实体类文件 - 只需要一个 SqlSugar.dll
生成实体就是这么简单,只要建一个T4文件和 文件夹里面放一个DLL. 使用T4模板教程 步骤1 创建T4模板 ,一定要自已新建,把T4代码复制进去,好多人因为用我现成的T4报错(原因不明) 点击添加文 ...
- VS编译器从DLL导出模板类
DLL与模板 http://msdn.microsoft.com/en-us/library/twa2aw10.aspx http://www.codesynthesis.com/~boris/blo ...
- [百度空间] [原]DLL导出实例化的模板类
因为模板是在编译的时候根据模板参数实例化的,实例化之后就像一个普通的类(函数),这样才有对应的二进制代码;否则,没有模板参数,那么编译器就不知道怎么生成代码,所以生成的DLL就没有办法导出模板了.但是 ...
- DLL中导出STL模板类的问题
接上一篇. 上一篇的dll在编译过程中一直有一个警告warning C4251: ‘CLASS_TEST::m_structs’ : class ‘std::vector<_Ty>’ ne ...
随机推荐
- .htaccess文件 使用
.htaccess文件 用法1:自错误页面 ErrorDocument 404 /error/404.html ErrorDocument 403/error/403.html 用法2:重定向 Red ...
- uva439 - Knight Moves(BFS求最短路)
题意:8*8国际象棋棋盘,求马从起点到终点的最少步数. 编写时犯的错误:1.结构体内没构造.2.bfs函数里返回条件误写成起点.3.主函数里取行标时未注意书中的图. #include<iostr ...
- linux make clean
make clean仅仅是清除之前编译的可执行文件及配置文件. 而make distclean要清除所有生成的文件. Makefile 在符合GNU Makefiel惯例的Makefile中,包含了一 ...
- 数据库连接池c3p0和dbcp
现在常用的开源数据连接池主要有c3p0.dbcp和proxool三种,其中: hibernate开发组推荐使用c3p0; spring开发组推荐使用dbcp(dbcp连接池有weblogic连接池同样 ...
- 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions
Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...
- HTML5 Video(视频)
HTML5 Video(视频) 很多站点都会使用到视频. HTML5 提供了展示视频的标准. 检测您的浏览器是否支持 HTML5 视频: 检测 Web站点上的视频 直到现在,仍然不存在一项旨在网页上显 ...
- sersync 实时同步工具
出处:http://code.google.com/p/sersync/ 当前版本的sersync依赖于rsync进行同步.如下图所示,在同步主服务器上开启sersync,将监控路径中的文件同步到目标 ...
- 从 Typecho 自定义字段的调用代码看去
千呼万唤,Typecho 的"自定义字段"功能终于在 0.9 中出来了.然而,多数人还蒙在这样一个鼓里--该怎么在模板调用已经设置好的自定义字段呢?让我们从这里开始说下去: Typ ...
- linux命令 chattr超级权限控件
linux命令:chattr 1.作用 修改ext2和ext3文件系统属性(attribute),使用权限超级用户. linux命令:chattr 1.作用修改ext2和ext3文件系统属性(at ...
- Kakfa揭秘 Day5 SocketServer下的NIO
Kakfa揭秘 Day5 SocketServer下的NIO 整个Kafka底层都是基于NIO来进行开发的,这种消息机制可以达到弱耦合的效果,同时在磁盘有很多数据时,会非常的高效,在gc方面有非常大的 ...