- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在查看有关导出函数的文档,它指出 __declspec(dllexport) 应该在命令行版本 -EXPORT: 之前使用,如果可能的话。我目前正在使用命令行变体。在尝试进行这些更改时,我试图了解正确的实现方式,但遇到了问题。
DLL的头文件:
#ifdef LIBRARY_EXPORTS
#define LIBRARY_API __declspec(dllexport)
#else
#define LIBRARY_API __declspec(dllimport)
#endif
#define PRINT_TEST(name) LIBRARY_API void name()
typedef PRINT_TEST(print_log);
// ^ What's the C++11 equivalent with the using keyword?
DLL的源文件:
PRINT_TEST(PrintTest) {
std::cout << "Testing DLL" << std::endl;
}
应用程序的源文件:
print_test* printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));
问题是因为 __declspec(dllexport) 包含在 typedef 中吗?因此,应用程序源文件中的语句实际上是:
__declspec(dllexport) void (*print_test)() printTest = reinterpret_cast<print_test*>(GetProcAddress(testDLL, "PrintTest"));
我没有收到任何编译器错误或警告。
最佳答案
问题是因为您正在导出一个 C++ 函数,它有一个损坏的名称。您要么需要将该损坏的名称传递给 GetProcAddress(从来都不是有趣的),要么您需要在函数声明中使用 __stdcall 取消导出
LIBRARY_API __stdcall void PrintTest
或使用 extern "C"
。 __stdcall
更简单,并将调用约定从 C++ 风格更改为 C 风格。 (由于 C 函数名称的导出方式,这可能需要将“_PrintTest”传递给 GetProcAddress。)
关于c++ - 使用 __declspec(dllexport) 而不是 -EXPORT :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34365367/
我有一个用 C 编写的可执行文件,其中包含一些我想从 c# 应用程序中使用的函数。我以前写过很多 dll 并且能够通过添加 __declspec(dllexport) 来使用它们中的函数。到函数声明。
我正在使用 RGiesecke DLLExport 库生成一个 C# DLL,它可以从基于 VC6 构建的遗留应用程序中动态加载。它导出方法并从 VC6 代码中调用它们。没问题。但是,只要我尝试为我的
我得到了这个庞大的项目,其中包含许多在 dll 文件中定义的类。我需要提取该项目的一部分并从该部分创建一个新项目。我已经设法通过使用 Visual Studio 中的代码映射找到了一些 dll 文件,
我已根据 MSDN 文档完成所有操作,但我的函数仍未导出。 LINK1 LINK2 LINK3 这是我的(2 个项目,DLL 和从 dll 导入的应用程序),看起来像这样(简短版): DLL 函数.h
我有一个加载 dll 的 exe。我都写了。 我正在导出一个返回 std::wstring 的函数 foo。 它所做的就是说 std::wstring blah = L"rgjwgfw"; ret
考虑一个简单的类,它只包含内联成员函数。例如: template class Point2D { public: typedef Point2D ThisType; typedef
我有我的dll项目 // .h #pragma once #include extern "C" { void __declspec(dllexport) __stdcall sort(int* v
Microsoft 说:“模板不能与使用 __declspec (dllimport) 或 __declspec (dllexport) 声明的函数一起使用。” (link)。 这是什么意思?我可以导
代码: #ifdef BUILD_DLL #define MY_API __declspec(dllexport) #else #define MY_API __declspec(dllimport)
您好,我对 dllexport 有点困惑。例如,当我在类里面使用 __declspec( dllexport ) 时 #define DllExport __declspec( dllexpor
我试图通过导出为 DLL(在 Windows/VS 2010 上)来保护一些 C++ 代码。 在下面的示例中,var 在父类(super class)构造函数中设置,并且调试器显示它肯定设置为引用某物
我现在正在使用 Visual Studio。我有一个经典的宏来标记 dll api 函数和类。我的理解是标记一个类 dllexport 可以使它的功能从其他二进制文件中可见,从而可以使用 dll 提供
我正在创建一个要在 C# 应用程序中使用的 C 包装器库。在我的 .c 中,函数定义如下: __declspec(dllexport) uint8_t aes132h_nonce(struct aes
这个问题可能类似于 DLL Exports: not all my functions are exported但由于那里没有完全回答,我不得不再问一次。我的情况也是因为使用模板和导出整个类略有不同。
现在我分析一些不是我写的旧代码。在 header 中有许多这样的声明: SVPDSDKDLLEXPORT inline C3vec mult(C3vec src, D3DXMATRIX &m); SV
#if COMPILING_DLL #define DLLEXPORT __declspec(dllexport) #else #define DLLEXPORT __declspec
我只是 c++ 的初学者,对我来说这似乎是不必要的代码膨胀。我知道 dllimport/export 用于共享 dll 功能,但仅使用公共(public)/私有(private)访问器有什么问题? 如
编辑 为了解决这个问题,我将以下内容添加到头文件(的开头): #ifdef GetMessage #undef GetMessage static inline BOOL GetMessage( LP
我正在考虑为名为 SmartDVB 的软件编写插件。它需要我导出以下函数(这是一个 C++ 示例): BOOL RegisterAddOn(UINT iAddOnId, IAddOnInterface
我想使用 dllexport 导出函数。但是我在编译器“错误 C4439:'WrappedC':签名中具有托管类型的函数定义必须具有 __clrcall 调用约定”时遇到错误。 我在头文件 (.h)
我是一名优秀的程序员,十分优秀!