SomeUser
SomeUser

Reputation: 2041

How to use the Windows API in MinGW?

How to use the Windows API in MinGW?

Upvotes: 33

Views: 50652

Answers (4)

Chang-Hui Kim
Chang-Hui Kim

Reputation: 9

After including

#include <Windows.h>
/* your toy windows program. */

I can use this command to build my toy example:

gcc main.c -mwindows

Upvotes: 0

Arty
Arty

Reputation: 16765

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/

Upvotes: 5

Rob
Rob

Reputation: 78758

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.

Upvotes: 8

Greg Hewgill
Greg Hewgill

Reputation: 994787

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.

Upvotes: 25

Related Questions