关于C Run-Time 在 crtdefs.h 中定义的分析

本文详细解析了C运行时库(CRT)的关键宏定义与配置选项,包括不同处理器架构下的库版本声明与链接器指令。适用于理解如何在多版本库共存的情况下保证程序的一致性和稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
crtdefs.h
/***
*crtdefs.h <CRT> C Run-Time
声明和定义<CRT>C运行时库 CRT CRT动态链接库(DLL) MSVCRTx0.DLL的所有命令。
*        Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*        此文件的部分的宏定义都用于整个 CRT 的使用。
*
*        [Public]
*
****/
 
/* Lack of pragma once is deliberate */
 
/* Define _CRTIMP */
// 定义 _CRTIMP C运行时库导出宏
#ifndef _CRTIMP
# ifdef _DLL
# define _CRTIMP __declspec(dllimport)
# else
# define _CRTIMP
# endif
#endif
 
#ifndef _INC_CRTDEFS
#define _INC_CRTDEFS
//定义微软接口定义语言
#if defined(_midl)
/*MIDL */
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT
#undef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDRD_NAMES 0
#define _CRT_SECURE_CPP_OVERLOAD_STANDRD_NAMES_COUNT 0
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 0
#endif
 
#if ! defined (_WIN32)
#error ERROR: Only Win32 traget supported!
#endif
 
#ifdef _CRT_NOFORCE_MANIFEST
 
 #ifdef _CRT_FORCE_MANIFEST
     #pragma message (_CRT_FORCE_MANIFEST and _CRT_NOFORCE_MANIFEST defined. Define just one )
     #pragma message (_CRT_FORCE_MANIFEST ignored)
 #endif
#else
 #if !defined(_CRT_FORCE_MANIFEST) && defined(_VC_NODEFAULTLIB)
   #define _CRT_NOFORCE_MANIFEST
#endif
//sal.h 用于对内存BUF的定义和调用方法的声明
#include <sal.h>
//处理两个以上引用了CRT,MFC,ATL的不同版本在一个程序的中的冲突问题
#if !defined (_CRT_NOFORCE_MANIFEST)
 
# ifdef _DEBUG
# ifdef _CRT_MANIFEST_RETALL
# define _CRT_MANIFEST_INCONSISTENT
# else
# define _CRT_MANIFEST_DEBUG
# define _CRT_MANIFEST_INCONSISTENT   //版本不一致
# else
# define _CRT_MANIFEST_RETALL
# endif
#endif
 
#ifdef _CRT_MANIFEST_INCONSISTENT
#error You have included some C++/C library header files with _DEBUG defined and some with _DEBUG not defined . this will not work correctly .Please have _DEBUG set or clear consistently,
#endif
//crtassem.h 定义CRT的版本等信息 常用 "8.0.50608.0"
#include <crtassem.h>
//CPU X86
#ifdef _M_IX86
# ifdef _DEBUG
#pragma comment (linker,/manifestdependency:/type=win32’    /
name=_LIBRARIES_ASSEMBLY_NAME_PREFIX.DebugCRT /
version=_CRT_ASSEMBLY_VERSION                /
processorArchitecture=x86’                        /
publicKeyToken= _VC_ASSEMBLY_PUBLICKEYTOKEN/)
#else
 #pragma comment (linker,/manifestdependency:/ type=Win32’ /
name= __LIBRARIES_ASEMBLY_NAME_PREFIX .CRT    /
version= _CRT_ASSEMBLY_VERSION               /
processorArchitecture=x86’                         /
 "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'/"")
#endif
#endif /* _M_IX86 */
//cpu AMD64
#ifdef _M_AMD64
# ifdef _DEBUG
#pragma comment (linker,/manifestdependency:/type=win32’    /
name=_LIBRARIES_ASSEMBLY_NAME_PREFIX.DebugCRT /
version=_CRT_ASSEMBLY_VERSION                /
processorArchitecture=amd64’                        /
publicKeyToken= _VC_ASSEMBLY_PUBLICKEYTOKEN/)
#else
 #pragma comment (linker,/manifestdependency:/ type=Win32’ /
name= __LIBRARIES_ASEMBLY_NAME_PREFIX .CRT    /
version= _CRT_ASSEMBLY_VERSION               /
processorArchitecture=amd64’                         /
 "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'/"")
#endif
#endif /* _M_AMD64 */
 
//IBM AXI 64
#ifdef _M_IA64
#ifdef _DEBUG
 #pragma comment (linker,/manifestdependency:/type=win32’    /
name=_LIBRARIES_ASSEMBLY_NAME_PREFIX.DebugCRT /
version=_CRT_ASSEMBLY_VERSION                /
processorArchitecture=ia64’                        /
publicKeyToken= _VC_ASSEMBLY_PUBLICKEYTOKEN/)
#else
 #pragma comment (linker,/manifestdependency:/ type=Win32’ /
name= __LIBRARIES_ASEMBLY_NAME_PREFIX .CRT    /
version= _CRT_ASSEMBLY_VERSION               /
processorArchitecture=ia64’                         /
 "publicKeyToken='" _VC_ASSEMBLY_PUBLICKEYTOKEN "'/"")
#endif
#endif /*_M_IA64 */
 
#endif /*__CRT_NOFORCE_MANIFEST */
 
#endif /*_DLL*/
 
 
#ifdef _MSC_VER
#undef _CRT_PACKING
#define _CRT_PACKING 8
#pragma pack (push,_CRT_PACKING)
#endif /*_MSC_VER */
 
#ifdef __cplusplus
Extern C {
#endif
 
/*预处理字符串*/
#ifndef _CRT_STRINGIZE
#define __CRT_STRINGIZE(_Value) #Value
#define _CRT_STRINGIZE(_Value) __CRT_STRINGIZE(_Value)
#endif
 
#ifndef _CRT_WIDE
#define _CRT_WIDE(_String) L ## _String
#define _CRT_WIDE(_String) __CRT_WIDE(_String)
#endif
 
#if !defined (_W64)
# if !defined(_midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER>=1300
# define _W64 __W64
# else
# define _W64
# endif
#endif
 
/* 定义 _CRTIMP_NOIA64 */
#ifndef _CRTIMP_NOIA64
# if defined (_M_IA64)
# define _CRTIMP_NOIA64
# else
# define _CRTIMP_NOIA64 _CRTIMP
# endif
#endif
 
/*定义 _CRTIMP2 */
#ifndef _CRTIMP2
# if defined (_DLL) && !defined(_STATIC_CPPLIB)
# define _CRTIMP2 __declspec(dllimport)
# else
# define _CRTIMP2
# endif
#endif
 
/*定义 _CRTIMP_ALTERNATIVE */
#ifndef _CRTIMP_ALTERNATIVE
#ifdef _DLL
# ifdef _CRT_ALTERNATIVE_INLINES
# define _CRTIMP_ALTERNATIVE
# else
# define _CRTIMP_ALTERNATIVE _CRTIMP
# define _CRT_ALTERNATIVE_IMPORTED
# endif
#else
# define _CRTIMP_ALTERNATIVE
#endif /*_DLL*/
#endif /* _CRTIMP_ALTERNATIVE */
 
/*定义 _MRTIMP */
//定义微软运行库
#ifndef _MRTIMP
#define _MRTIMP __declspec(dllimport)
#endif
 
/*定义 _MRTIMP2 */
#ifndef _MRTIMP2
 
# if defined (_DLL)
# define _MRTIMP2 __declspec(dllimport)
# else
# define _MRTIMP2
# endif
#endif
 
#ifndef _MCRTIMP
# ifdef _DLL
# define _MCRTIMP __declspec(dllimport)
# else
# define _MCRTIMP
# endif
#endif
 
#ifndef __CLR_OR_THIS_CALL
# if defined(MRTDLL) || defined (_M_CEE_PURE)
# define __CLR_OR_THIS_CALL __clrcall
# else
# define __CLR_OR_THIS_CALL
# endif
#endif
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值