在DLL中导出另一静态库中的函数
2015-06-24 20:26
246 查看
开发环境:
win7_x64、VS2013
应用场景:
动态库A依赖动态库B,而动态库B又使用了静态库C;有些情况下,我们需要将C从B里面导出,然后提供给A使用。
正文:
Step1:
1、新建测试静态库TestStatic
2、添加TestA.h、TestA.cpp、TestB.h和Testb.cpp文件
3、添加以下代码导出TestA类和testB函数
TestA.h
TestA.cpp
TestB.h
TestB.cpp
Step2:新建测试动态库TestDll
1、在TestDll.cpp文件中添加以下代码,从当前DLL中导出TestA类和test函数
TestDll.cpp
Step3:编译项目TestStatic和项目TestDll,在生成的TestDll.dll中可利用DEPENDS.EXE工具查看导出函数
win7_x64、VS2013
应用场景:
动态库A依赖动态库B,而动态库B又使用了静态库C;有些情况下,我们需要将C从B里面导出,然后提供给A使用。
正文:
Step1:
1、新建测试静态库TestStatic
2、添加TestA.h、TestA.cpp、TestB.h和Testb.cpp文件
3、添加以下代码导出TestA类和testB函数
TestA.h
#pragma once #if defined _Use_Static_Export_ #define _Static_Export_ _declspec(dllexport) #elif defined _Use_Static_Import #define _Static_Export_ _declspec(dllimport) #else #define _Static_Export_ #endif class TestA { public: _Static_Export_ TestA(); _Static_Export_ ~TestA(); _Static_Export_ int test(); _Static_Export_ void testb(); };
TestA.cpp
#include "TestA.h" TestA::TestA() { int i = 10; } TestA::~TestA() { int i = 10; } int TestA::test() { return 10; } void TestA::testb() {}
TestB.h
#pragma once #if defined _Use_Static_Export_ #ifndef _Static_Export_ #define _Static_Export_ __declspec(dllexport) #endif #elif defined _Use_Static_Import #ifndef _Static_Export_ #define _Static_Export_ __declspec(dllimport) #endif #else #ifndef _Static_Export_ #define _Static_Export_ #endif #endif namespace Test { _Static_Export_ void testB(); }
TestB.cpp
#include "TestB.h" namespace Test { void testB() {} }
Step2:新建测试动态库TestDll
1、在TestDll.cpp文件中添加以下代码,从当前DLL中导出TestA类和test函数
TestDll.cpp
#define _Use_Static_Export_ #include "./../TestStatic/TestA.h" #include "./../TestStatic/TestB.h" void dll_export() { TestA a; Test::testB(); }
Step3:编译项目TestStatic和项目TestDll,在生成的TestDll.dll中可利用DEPENDS.EXE工具查看导出函数
相关文章推荐
- Sicily 1443. Printer Queue
- 第三方SDPieProgressView 下拉刷新tableView
- IO流总结(一)
- 为什么要写博客?
- 在DLL中导出另一静态库中的函数
- 抽象类
- 静态顺序表
- 代理模式
- Linux下write、read方式
- ArcGIS API for Javascript 应用开发入门
- uva--242(邮资问题 dp)
- 二叉树的递归遍历
- Java知多少(102)多媒体基础
- JAVA NIO的selector的实现原理
- iOS 上下有黑边
- DNS服务器 与 域名解析
- Sicily 1931. 卡片游戏
- 获取Android设备挂载的所有存储器
- MAC 命令行 HomeBrew ,RubyGems, Node.js详解
- 关于使用google earth 截取数据与ground truth 制作