加一个有点意思的宏
#define WINAPI_PARTITION_PKG_WINTRUST (WINAPI_PARTITION_SERVER == 1)
这个实际是一个递归使能的宏,形成树状宏定义,根节点变更,所有递归节点都变更
//<corecrt.h>注释
//杂项,几个常量、宏
#define _ARGMAX 100
#define _TRUNCATE ((size_t)-1)
#define _CRT_INT_MAX 2147483647
#define _CRT_SIZE_MAX ((size_t)-1)
//宽字符常量
#define __FILEW__ _CRT_WIDE(__FILE__)
#define __FUNCTIONW__ _CRT_WIDE(__FUNCTION__)
//static_assert的替代实现方式,在老版本服务器上可以实现告警。
#define _STATIC_ASSERT(expr) typedef char __static_assert_t[(expr) != 0]
#define _CRT_UNUSED(x) (void)x //UNUSED宏的标准定义
#ifdef _DEBUG
_ACRTIMP void __cdecl _invalid_parameter(
_In_opt_z_ wchar_t const*,
_In_opt_z_ wchar_t const*,
_In_opt_z_ wchar_t const*,
_In_ unsigned int,
_In_ uintptr_t
);
#endif
_ACRTIMP_ALT void __cdecl _invalid_parameter_noinfo(void);
_ACRTIMP __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(void);
__declspec(noreturn)
_ACRTIMP void __cdecl _invoke_watson(
_In_opt_z_ wchar_t const* _Expression,
_In_opt_z_ wchar_t const* _FunctionName,
_In_opt_z_ wchar_t const* _FileName,
_In_ unsigned int _LineNo,
_In_ uintptr_t _Reserved);
//debug时输出信息,非debug时不输出
#ifndef _CRT_SECURE_INVALID_PARAMETER
#ifdef _DEBUG
#define _CRT_SECURE_INVALID_PARAMETER(expr) ::_invalid_parameter(_CRT_WIDE(#expr), __FUNCTIONW__, __FILEW__, __LINE__, 0)
#else
#define _CRT_SECURE_INVALID_PARAMETER(expr) ::_invalid_parameter_noinfo_noreturn()
#endif
#endif
//弃用和警告
#define _CRT_WARNING_MESSAGE(NUMBER, MESSAGE) \
__FILE__ "(" _CRT_STRINGIZE(__LINE__) "): warning " NUMBER ": " MESSAGE
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
#define _CRT_NONSTDC_DEPRECATE(_NewName) _CRT_DEPRECATE_TEXT( \
"The POSIX name for this item is deprecated. Instead, use the ISO C " \
"and C++ conformant name: " #_NewName ". See online help for details.")
//__declspec(process)是一种Windows特有的调用约定,它指定函数运行在独立的进程中。
#define _PGLOBAL __declspec(process)
//__declspec(appdomain) 应用于一个函数,那么这个函数会在指定的应用程序域中进行执行
#define _AGLOBAL __declspec(appdomain)
//windows下_Field_range_(min_expr, max_expr) 属性来指定一个变量的值域范围限制
_Field_range_(1, 2) int _locale_mb_cur_max;
//C++安全重载生成宏 C++ Secure Overload Generation Macros
//对C函数进行重新包装,增强安全性
#define __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(_ReturnType, _FuncName, _DstType, _Dst, _TType1, _TArg1)\
extern "C++"{\
template <size_t _Size>\
inline _ReturnType __CRTDECL _FuncName(_DstType (&_Dst)[_Size], _TType1 _TArg1) _CRT_SECURE_CPP_NOTHROW{ \
return _FuncName(_Dst, _Size, _TArg1);\
}\
}
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(char*, strncpy_s, char, dest, const char*, src)
strncpy_s(dest, sizeof(dest), src, _TRUNCATE);
//通过宏、模板对c运行时库的函数进行了二次封装,增强安全性