Is #include bad practice?

Msdn documentation explicitly tells you (a) in which header file a function is declared and (b) which header file you are supposed to include.

Most functions tell you to include windows.h, for example SendMessage

Some function, that were added later or have very specific use cases, are only available through other header files, for example SetupDiEnumDeviceInfo.

So no, it is not bad practice to follow their advice. However, I strongly recommend disabling some parts of it before including via macro, e.g.

#define NOMINMAX
#include <Windows.h>

because otherwise you will get a min and a max macro that will interfere with std::min and std::max.

Leave a Comment

tech