1.windows环境预定义宏 WIN32、_WIN32、_WIN64
1.1 basic
-
WIN32宏
只要包含了 Windows.h,那么 WIN32 常量是肯定定义了的,所以不能用于判断平台环境 -
_WIN32
32位和64位程序都有,且总是定义的. -
_WIN64
只有64位程序才有,故此宏用来判断环境是 ×86 还是 ×64.
1.2 common code
1.2.1 判断是不是 windows 平台
#if _WIN32 || WIN32 //windows平台
...
#else
...
#endif
1.2.2 判断是 64 位环境还是 32 位
#ifdef _WIN64
#ifdef _DEBUG
#pragma comment(lib, "*x64d.lib")
#else
#pragma comment(lib, "*x64r.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib, "*x86d.lib")
#else
#pragma comment(lib, "*x86r.lib")
#endif
#endif