Background: I want to enable NVIDIA optimus by default. The solution recommended by NVIDIA is to use extern "C" _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
.
Therefore I need DWORD
to be defined.
I have read this question which asks for the minimum header that defines DWORD
with the best solution being to define WIN32_LEAN_AND_MEAN
and still use windows.h or to define it yourself because it is unlikely to change.
In contrast to the mentioned question I have no problem with the size of windows.h in itself (none issue when using precompiled headers). I would however like to avoid to clutter the global namespace with all its types, functions etc. especially since I only need one type for one line of code.
TLDR: Is there any way to include the header but have all of its content only available in a limited scope?
Note that you can't simply include the header in a namespace like so:
namespace encloseWindowsTypes {
#include <Windows.h>
extern "C" _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}
since part of the windows.h relies on previous part of it being defined in global namespace and you would get errors like 'div_t': is not a member of '`global namespace''
.
User contributions licensed under CC BY-SA 3.0