全局的.dll头文件
Global in .dll Header
我有一个.dll头声明一个类。
在类声明之后实例化类的静态对象。
.dll导出的函数与静态对象的接口。
当第一次调用这些导出函数之一返回时,我得到一个无法解释的段错误。所以我的问题是:是可以声明一个静态对象在.dll头像这样:
class Foo{
public:
void bar();
};
static Foo foo;
__declspec( dllexport ) void func() { foo.bar(); }
对于您正在尝试的,您需要从头文件中完全删除类,它根本不属于那里。
试试这样写:
MyDll.h(与想要使用您的DLL的项目共享):
#ifndef MyDllH
#ifdef BUILDING_DLL
#define MYDLL_EXPORT __declspec( dllexport )
#else
#define MYDLL_EXPORT __declspec( dllimport )
#endif
#ifdef __cplusplus
extern "C" {
#endif
MYDLL_EXPORT void func();
// other functions as needed...
#ifdef __cplusplus
}
#endif
#endif
MyDll.cpp:(仅作为DLL项目的一部分编译):
#define BUILDING_DLL
#include "MyDll.h"
class Foo
{
public:
void bar();
};
void Foo::bar()
{
//...
}
static Foo foo;
void func()
{
foo.bar();
}
// other functions as needed...
相关文章:
- 挂起和取消挂起一个文件DLL
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- 将 dll 文件注入 UWP
- 加载"D:UsersPublicDocumentsopencvbuildx64vc14binopencv_world340d.dll",找不到或打开PDB文件
- CMake 生成的 MSVC 项目找不到符号,即使为其相关 dll 正确生成了 lib 文件也是如此
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 在使用 Clang 编译 DLL 时指定 DEF 文件
- 从 .lib 文件创建一个.dll文件
- 可执行文件C++包括.obj,.lib和.dll吗?
- python37.dll在可执行文件中未链接
- 链接器找不到导入的 DLL 的 LIB 文件
- DLL:当 SDK 头文件不使用 __declspec(dllexport) 时,我可以使用它吗
- sf::Windows上的音乐:api-ms-win-crt-locale-l1-1-0.dll:无法打开共享对象文件
- 如何在 CMake 超级生成中查找 dll/so 文件
- 在任何平台上执行任何Qt5应用程序的重要dll文件是什么(运行时文件dll)
- 在C++的应用程序中包括文件(dll,txt等.exe
- 反编译文件.dll
- 另一台电脑上的C++程序所需的文件/DLL