在DLL中导出另一静态库中的函数

您所在的位置:网站首页 查看动态库导出函数的方法 在DLL中导出另一静态库中的函数

在DLL中导出另一静态库中的函数

2024-07-10 09:17| 来源: 网络整理| 查看: 265

开发环境: 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工具查看导出函数



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3