I have a small project in mind that requires the usage of the Win32 API in C++.
I lack some knowledge concerning the building steps of such an app, so I would like to do it without using Visual Studio, to teach myself how things are working under the hood.
To do so, I got VS Code, MinGW, Make for Windows, and the Win32 API.
After some time figuring out how MinGW and the Make tool work, I'm trying to get my head around libraries and dependencies.
Doing so, I want to compile this truly simple code:
/*
header file coming from the win32 api,
giving access to the Windows Wallpaper, which is what I want to mess with
*/
#include "ShObjIdl_core.h"
int main() {
return 0;
}
Within my Makefile, I include the two folders where the win32's header files I want are stored:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0
\um
\Shared
The linkage seems successful, but here comes the issue: the compiler is throwing at me a ton of different errors coming from a lot of different files.
Here's a few examples:
- error: #error "No Target Architecture"`
- warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
#pragma warning(disable:4214) // bit field types other than int
- error: cast from 'const void*' to 'long unsigned int' loses precision [-fpermissive]
return((void *) (ULONG_PTR) (unsigned long) p);
- error: 'PCONTEXT' was not declared in this scope;
I've seen here that I should #include "windows.h"
instead of my specific file, but this doesn't solve the issue, I still get a bunch of errors.
I feel I'm missing an important bit about working with an API, or with dependencies in general, but I just can't find anything on the web to help me understand how this is supposed to work.
MinGW comes with its own Win32 API headers and libraries.
So don't mix this with headers from Microsoft.
Simply using #include <windows.h>
should be sufficient.
The MinGW GCC compiler will know where to find it.
For linking you will need to add the necessary -l
flags, and for those too MinGW GCC will know where to look.