How to use the Windows API in MinGW?
Solution 1
Whenever I've done this, I just
#include <windows.h>
and start coding. MinGW comes with a windows.h
file so you don't need to do anything extra.
Solution 2
I occasionally use the Windows API for Qt apps that I build using Qt Creator/MinGW - I just #include
the appropriate Windows SDK header (the headers come with MinGW) and it just works. However, you may need to #define
a few things in order that some API calls are exposed. For example, I recently needed to call SHGetSpecialFolderPath
(found in shlobj.h
) but needed to define _WIN32_IE
to 0x0400
first.
Solution 3
In case if you installed MinGW as a part of MSYS on Windows then you can install Windows.h
and other Win-API headers through following command inside MSYS shell:
pacman -S msys2-w32api-headers msys2-w32api-runtime
then header is located in
c:/MSYS_PATH/usr/include/w32api/windows.h
also you can search any package name (or sub-name) through e.g.
pacman -Ss w32api
If you're on Linux then Windows.h
can be installed through
sudo apt install mingw-w64-common
then header is located here
/usr/share/mingw-w64/include/windows.h
you may probably need to include compiler's option
-I/usr/share/mingw-w64/include/
Comments
-
SomeUser about 3 years
How to use the Windows API in MinGW?
-
Andrejs Cainikovs over 14 yearsIt is wrong to tell that MinGW comes with windows.h. People like me, who prefers copying latest packages and building MinGW by yourself (not using installer), should copy w32api package from MinGW download site.
-
jondinham over 11 yearsmy mingw has that header file, but it fails to link
-
Tanz87 almost 4 yearsThe need to
#define _WIN32_IE
is described here.