C++ DLL 模板 .
睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接
C++ DLL 模板
1、使用VS2005創建Win32 DLL項目,選擇空項目,然后加入CppDll.h和CppDll.cpp文件。
2、修改CppDll.h和CppDll.cpp文件使之成為需要的內容。
3、編譯生成CppDll.dll。
下面是模板文件:
[cpp] view plaincopyprint?- //
- // 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__
[cpp] view plaincopyprint?
- //
- // 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;
- }
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成