C++无法使用GDI编译dll+
我的 TestDLL.cpp 代码如下所示:
#ifdef DLL_EXPORTS
__declspec(dllexport) void test();
#else
__declspec(dllimport) void test();
#endif
#include "stdafx.h"
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
void test()
{
GdiplusStartupInput gdiplusStartupInput;
}
现在,当我尝试编译 dll 时,GDI+ 的头文件中有 100 多个错误。 然而,GDI+ 在我的控制台应用程序(exe)上工作(编译)良好。 GDI+ 不与 DLL 兼容吗?并且 gdiplus.lib 已链接,以防有人询问...
My TestDLL.cpp code looks like this:
#ifdef DLL_EXPORTS
__declspec(dllexport) void test();
#else
__declspec(dllimport) void test();
#endif
#include "stdafx.h"
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
void test()
{
GdiplusStartupInput gdiplusStartupInput;
}
Now when im trying to compile the dll there are 100+ errors from header files of GDI+.
However the GDI+ works(compiles) fine on my console application (exe). Isn't GDI+ compatible with DLL's or what? And the gdiplus.lib is linked incase someone asks it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也有同样的问题。以下行修复了它。
我希望这有帮助。
I had the same problem. The following line fixed it.
I hope this helps.
将其放入预编译头中
Put this inside your precompiled header
这些错误可能是由于定义的宏无效造成的,请参阅此 MS 文章
The errors are likely due to invalid macros defined, see this MS article
您可能需要将 gdi+ 添加到您的项目链接的库中。检查项目属性。
You probably need to add gdi+ to the libraries your project is linking against. Check the project properties.
像
using namespace gdiplus;
这样的行很危险,因为它们会将所有内容从该命名空间拉到当前命名空间中。当您构建 DLL 时,这可能会导致链接问题。这些标头之一也可能使用相同的
DLL_EXPORTS
,但是前几条错误消息的样本将使人们更容易帮助您。
Lines like
using namespace gdiplus;
are dangerous in that they pull everything from that namespace into the current namespace. This can lead to problems linking when you're building a DLL.It's also possible that one of those headers is using the same
DLL_EXPORTS
But a sampling of the first few error messages would make it a lot easier for people to help you.
我也是在使用 GDI+ 编译 DLL 时遇到大量错误之后来到这里的。然而,所有答案都不适用于我的情况。
我的 DLL 中出现错误的原因是定义了宏 WIN32_LEAN_AND_MEAN。
因此,当您收到 GDI+ API/类型的此类错误时,请确保不会为您定义此宏。
要解决此问题,请删除此宏的任何定义(如果可以找到它们),或者在包含任何平台头文件之前在源文件顶部取消它们的定义,如下所示:
I also came here after getting numerous errors when compiling my DLL using GDI+. However, none of the answers applied to my case.
Reason for my getting errors in my DLL was defining the macro WIN32_LEAN_AND_MEAN.
So, make sure this macro does not get defined for you when you get such errors for GDI+ APIs/types.
To resolve, remove any definitions of this macro (if you can find them) or undefine them at the top of your source file before you include any of the platform header files like so: