我的开发环境:
Windows 7 64位
Code :: blocks 13.12 with MinGW编译器。
更改了Code :: blocks中的设置 - 仅限于设置 - >编译器 - >链接器设置 - >其他链接器选项:-static-libgcc -static-libstdc++
这是我失败的代码: 主:
#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;
}
主代码(名为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;} \
/// --------------------------------------------------------------------------------------------------
问题:
排队失败Graphics* hGraphics = Graphics::FromHWND(hwnd,false);
当我尝试运行时,我收到此错误:
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))
我花了很多时间......我不知道该怎么办。我意识到我需要Gdiplus的“def”文件。 我发现了这个:https://sourceforge.net/u/earnie/winapi/winapi/ci/master/tree/lib/gdiplus.def
我尝试在链接器设置中添加它(在编译器 - &gt;链接器设置 - >其他链接器选项中):-def gdiplus.def
。
在这种情况下,错误是相同的,但这次与不同的东西 -
在编译期间,它打印了很多关于从dll中提取函数的错误。它无法从dll中提取所有函数。具有相同错误消息的所有失败... symbol not definded
我感到有点迷茫......我在Google上寻找解决方案,但它没有帮助..我是C ++的新手
感谢帮助者!
答案 0 :(得分:0)
将-lgdiplus
添加到链接器选项。