查看Win32 下动态链接库 (DLL) 机制笔记的源代码
←
Win32 下动态链接库 (DLL) 机制笔记
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== DLL 中导出C++ 类 == 与导出 C 风格的函数类似,在定义类时用 __declspec(dllexport): <pre> class __declspec(dllexport) MyCppClass { ...... }; </pre> 编译时,依然用: cl /Fesimple.dll /LD smiple.cc 加载时动态链接,则要在使用前加 __declspec(dllimport) 声明之: class __declspec(dllimport) MyCppClass; 如下所示列: <pre> ---------- comcat.h: ---------- #ifndef _MY_CMATH_H_ #define _MY_CMATH_H_ #ifdef _CLASS_INDLL_ #define _CLASS_DECL_ __declspec(dllexport) #else #define _CLASS_DECL_ __declspec(dllimport) #endif class _CLASS_DECL_ CMath { public: int Add(int a,int b); CMath(); ~CMath(){}; }; #endif </pre> comcat.cc: <pre> #include "comcat.h" CMath::CMath() { }; int CMath::Add(int a, int b) { return a + b; } </pre> 如下命令生成 DLL: cl /LD /Fecomcat.dll /D_CLASS_INDLL_ comcat.cc <br><br> === 加载时动态链接测试 === class.load.test.cc <pre> #include "comcat.h" #include <iostream> int main() { CMath *cm = new CMath; std::cout << "cmath's result:" << cm->Add(5, 8) << std::endl; return 0; } </pre> 如下命令编译之: cl /Feclass.load.test.exe class.load.test.cc comcat.lib <br><br><br><br> <br><br> <br><br>
返回到
Win32 下动态链接库 (DLL) 机制笔记
。
个人工具
3.14.11.50
该IP地址的讨论
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面