原文:http://support.microsoft.com/kb/130869 In Microsoft Visual C++, if the version of the compiler i

原文:http://support.microsoft.com/kb/130869

In Microsoft Visual C++, if the version of the compiler is older than a specific version, a GUID must be initialized exactly once. For this reason, there are two different versions of the DEFINE_GUID macro. One version just declares an external reference to the symbol name. The other version actually initializes the symbol name to the value of the GUID. If you receive an LNK2001 error for the symbol name of the GUID, the GUID was not initialized.
在VC中,如果编译器的版本比某个特定版本老,一个GUID的被初始化只能而且必须执行一次。由于这个原因,有两个版本的DEFINE_GUID宏。一个版本只是声明对符号名的外部引用;另一个版本会初始化这个符号名为其GUID值。如果碰到GUID的符号名的LNK2001错误,是因为GUID没有被初始化。
Note The DEFINE_GUID macro in the guiddef.h header file declares a GUID. To also define the GUID, include the INITGUID.H header file in the source file where the GUID should be defined.

You can make sure your GUID gets initialized in one of two ways:

  • If you are using precompiled header files, include the INITGUID.H header file before defining the GUID in the implementation file where it should be initialized. (AppWizard-generated MFC projects use precompiled headers by default.) 如果使用预先编译的头文件,实现文件中在定义GUID之前,包含INITGUID.h头文件。
  • If you are not using precompiled headers, define INITGUID before including OBJBASE.H. (OBJBASE.H is included by OLE2.H.)如果没有使用预先编译的头文件,在包含OBJBASE.h前定义INITGUID。

Note If the version of the compiler is newer than a specific version, when you are using precompiled headers, you can include the INITGUID.H header file in a single header file that includes other header files. This will cause the GUID to be defined in all the source files where this header file is included. You will not receive an LNK2001 error even if a symbol is defined multiple times. This is because a DECLSPEC_SELECTANY keyword is used in the DEFINE_GUID macro. This keyword makes sure that the linker will correctly handle this multiple definition.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值