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 ...
随机推荐
- iOS开发——打包ipa
首先,保证设备证书和配置文件的正确,Xcode上登陆好自己公司的账号Apple ID 1.选中运行模拟器的位置为硬件设备 2.点击导航栏上的[Product]——[Archive]后编译后弹出如下界面 ...
- CSS常见的浏览器前缀
为了让浏览器识别某些专属属性,有时候需要在CSS属性前增加浏览器前缀 -ms-:Microsoft IE -moz-:Mozilla Firefox -o-:Opera Opera -webkit-: ...
- System.Windows.Forms.Timer反编译学习
using System; using System.ComponentModel; using System.Globalization; using System.Runtime; using S ...
- Tomcat遇到的问题The Tomcat server configuration at ServersTomcat v5.5 Server at localhost-config is missing. Check..
一.解决方法 删除Servers视图,重新创建一个即可.
- 何谓IOC的核心思想
IOC(Inversion of Control)即控制反转,是在面试或平常交流中经常遇到了词汇:我也曾经仿照Spring,利用JDK的反射和动态代理实现了一个简单的IOC框架,感觉算是知其然也知其所 ...
- 在HTML5中怎样实现Canvas阴影效果
该文章是由e良师益友技术部小陈原创作品,转载是请注明来源,谢谢! 今天我给大家介绍一下在HTML5中怎样实现Canvas阴影效果,我们知道现在HTML5的Canvas阴影也经常使用的,这个就是HTML ...
- 【转】JS函数的定义与调用方法
JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式:先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来 ...
- Tomcat & Nginx
http://cxshun.iteye.com/blog/1535188 反向代理方式实际上就是一台负责转发的代理 服务器,貌似充当了真正服务器的功能,但实际上并不是,代理服务器只是充当了转发的作用, ...
- 前端encodeURIComponent 和后端http_build_query配合
解决特殊字符不能转义 1. function fixedEncodeURIComponent (str) { return encodeURIComponent(str).replace(/[!' ...
- Pandas之容易让人混淆的行选择和列选择
在刚学Pandas时,行选择和列选择非常容易混淆,在这里进行一下讨论和归纳 本文的数据来源:https://github.com/fivethirtyeight/data/tree/master/fa ...