全局外部指针变量在 DLL 中不可见
Global extern pointer variable not visible in DLL
>我有一个主应用程序EXE "main.EXE"。我在头文件 globalf.h 中创建了一个全局指针,其中包含 extern,如下所示:
全球F.H
extern SomeClass* cPtr;
现在在主.EXE代码中
#include globalf.h
INitialize()
{
cPtr = new SomeClass(); // works fine.
D.DLL:
#include "globalf.h"
void DllFunc()
{
cPtr->someFunction1(); // link error unreslved external symbol.
我无法访问 DLL 代码中的全局指针变量,即使 虽然我已经声明了 inMain.EXE 代码。
我大体上知道这个宣言。EXE 的 Initialize(( 对 不可见 DLL。但是我该如何实现这一点呢?有没有办法C++处理 跨 DLL 和 EXE 的此类全局变量。
我不是导出全局指针变量,而是将其以及您需要在 EXE 和 DLL 之间共享的其他变量打包在一个结构中,然后将指向该结构的指针作为函数参数传递给 DLL 初始化函数。
// Function exported from the DLL.
// Called by the EXE during initialization.
//
// The DLL receives a pointer to the global state structure,
// shared between the EXE and the DLL.
//
BOOL YourDllInit(GlobalStuff* pGlobal);
相关文章:
- C++:将外部库链接到dll库
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 将 c++ 生成器应用程序与外部 dll 结合使用
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 加载由 MATLAB Coder 生成的带有函数的 DLL,该函数调用外部函数
- 外部"C"与类和 DLL
- 如何将外部 dll 添加到我的 VS2019 项目?
- DLL+导出类+模板成员func=未解析的外部符号.任何修复的机会
- 全局外部指针变量在 DLL 中不可见
- 外部 "C" Visual Studio 2015 中的显式类型错误,DLL 测试代码
- 尝试针对 dll 链接时未解析的外部
- 放置在外部 DLL 中的类中的字符串数据的内存损坏
- 从dll传递c字符串,穿过外部C
- 将 C 中的外部 DLL 追加到 C# 中的 WinForm 项目
- 如何包含具有多个 dll/dylib 的外部(共享)库
- C++ DLL:未解析的外部符号
- 如何调试在外部C#应用中旋转的C DLL(从调试器无法启动)
- 当您的外部SDK仅具有.dll,.lib,.h文件时,如何链接和构建项目
- 未解决的外部符号,带有ftd3xx.dll
- 在VS中编译程序,无需外部运行时DLL