Native Windows API issue on Qt + win32 + mingw
I am trying to use native Windows API with Qt using the mingw toolbox. There are problems with some functions. What's happening? Is this a bug with the mingw name change?
#ifdef Q_WS_WIN
HWND hwnd = QWidget::winId();
HDC hdcEMF = CreateEnhMetaFile(NULL, NULL, NULL, NULL ) ;
Rectangle(hdcEMF,100,100,200,200);
HENHMETAFILE hemf = CloseEnhMetaFile(hdcEMF);
OpenClipboard(hwnd);
EmptyClipboard();
SetClipboardData(CF_ENHMETAFILE,hemf);
CloseClipboard();
#else
Errors:
undefined reference to "CreateEnhMetaFileW @ 16"
undefined reference to `Rectangle @ 20 '
undefined reference to `CloseEnhMetaFile @ 4 '
source to share
The functions CreateEnhMetaFileW()
and are CloseEnhMetaFile()
defined in the static library Gdi32.lib, so you must be sure to link it. Try adding -lgdi32
to the end of your command line that you are using to compile. If that doesn't work, you may need to provide the full path to Gdi32.lib by adding it instead -L/path/to/folder/containing/the/library -lgdi32
.
source to share
It is possible that the functions are included but become crippled due to the C ++ assumption.
Look at the extern C {} expression. It is designed to declare functions that should not be named malformed to account for polymorphism / overloading. (IE has two functions with the same name).
source to share