[英]C++ Using Gdiplus in Code::Blocks with MinGW compiler
My development environment: Windows 7 64bit Code::blocks 13.12 with MinGW compiler.我的开发环境: Windows 7 64bit Code::blocks 13.12 with MinGW compiler。 Changed settings in Code::blocks - only in settings -> compiler -> linker settings -> other linker options: -static-libgcc -static-libstdc++
更改了 Code::blocks 中的设置 - 仅在设置 -> 编译器 -> 链接器设置 -> 其他链接器选项: -static-libgcc -static-libstdc++
This is my failed code: Main:这是我失败的代码:主要:
#include "main.h"
#include <iostream>
#include <objidl.h>
#include <Gdiplus.h>
using namespace std;
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
MainCode /// Look better even then main() :).
{
Execute_InitializeWindow; /// Initialize root window (For WinGUI)
HWND hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW | WS_VISIBLE, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
Graphics* hGraphics = Graphics::FromHWND(hwnd,false); /// <---------------- HERE IT FAILS!
/// Massage handler
while (1){ if (GetMessage (&msg, NULL, 0, 0) <= 0) {break;}
/* Translate virtual-key messages into character messages */
TranslateMessage(&msg);
//cout << msg << endl;
/* Send message to WindowProcedure */
DispatchMessage(&msg);
}
return msg.wParam; // The program return-value is 0 - The value that PostQuitMessage() gave
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc (hwnd, message, wParam, lParam);
switch (message) /* handle the messages */
{
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
//cout << 1;
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Heder for the main code (named as main.h):主代码的 Heder(命名为 main.h):
#include <windows.h>
/// ---------------------------------------- Codes for Initialize of main GUI -----------------------------------------
#define MainCode int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nCmdShow)
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); // Declare Windows procedure
TCHAR szClassName[ ] = "my_program_root_name";
#define Execute_InitializeWindow \
\
MSG msg; \
\
WNDCLASSEX wincl; \
wincl.hInstance = hThisInstance; \
wincl.lpszClassName = szClassName; \
wincl.lpfnWndProc = WindowProcedure; \
wincl.style = CS_DBLCLKS; \
wincl.cbSize = sizeof (WNDCLASSEX); \
\
\
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); \
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); \
wincl.hCursor = LoadCursor (NULL, IDC_ARROW); \
wincl.lpszMenuName = NULL; \
wincl.cbClsExtra = 0; \
wincl.cbWndExtra = 0; \
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; \
\
if (!RegisterClassEx (&wincl)) {return 1;} \
/// --------------------------------------------------------------------------------------------------
Problem: Failing in line Graphics* hGraphics = Graphics::FromHWND(hwnd,false);
问题:无法在线Graphics* hGraphics = Graphics::FromHWND(hwnd,false);
When I try to run this, I get this error:当我尝试运行它时,出现此错误:
mingw32-g++.exe -c "D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.cpp" -o "D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o"
mingw32-g++.exe -o "D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.exe" "D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o" -static-libgcc -static-libstdc++
D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o:main.cpp:(.text$_ZN7Gdiplus11GdiplusBasenwEj[__ZN7Gdiplus11GdiplusBasenwEj]+0xd): undefined reference to `GdipAlloc@4'
D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o:main.cpp:(.text$_ZN7Gdiplus11GdiplusBasedlEPv[__ZN7Gdiplus11GdiplusBasedlEPv]+0xd): undefined reference to `GdipFree@4'
D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o:main.cpp:(.text$_ZN7Gdiplus8GraphicsC1EP6HWND__i[__ZN7Gdiplus8GraphicsC1EP6HWND__i]+0x3a): undefined reference to `GdipCreateFromHWNDICM@8'
D:\גיבויים\DATA\Desktop\cpp gdi plus problem\main.o:main.cpp:(.text$_ZN7Gdiplus8GraphicsC1EP6HWND__i[__ZN7Gdiplus8GraphicsC1EP6HWND__i]+0x57): undefined reference to `GdipCreateFromHWND@8'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
4 error(s), 0 warning(s) (0 minute(s), 1 second(s))
I spend a lot of time on it .. I do not know what to do.我花了很多时间在上面.. 我不知道该怎么办。 I realized that I need "def" file for Gdiplus.我意识到我需要 Gdiplus 的“def”文件。 I found this: https://sourceforge.net/u/earnie/winapi/winapi/ci/master/tree/lib/gdiplus.def我发现了这个: https : //sourceforge.net/u/earnie/winapi/winapi/ci/master/tree/lib/gdiplus.def
And I tried to add it in the linker settings by adding this (in compiler -> linker settings -> other linker options): -def gdiplus.def
.我尝试通过添加以下内容(在编译器 -> 链接器设置 -> 其他链接器选项中)将它添加到链接器设置中: -def gdiplus.def
。 In this case the error was the same but this time with something different - during compile time, It prints lots of error about extracting functions from the dll.在这种情况下,错误是相同的,但这次有一些不同 - 在编译期间,它打印了很多关于从 dll 中提取函数的错误。 it failed to extract all functions from the dll.它未能从 dll 中提取所有函数。 All failures with the same error message ... symbol not definded
具有相同错误消息的所有失败... symbol not definded
I feel a little lost .. I looked for solutions on Google but it did not help .. I am very new in C ++我觉得有点迷茫..我在谷歌上寻找解决方案,但没有帮助..我对 C++ 很陌生
Thanks for helpers!感谢各位帮手!
将-lgdiplus
添加到您的链接器选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.