zoukankan      html  css  js  c++  java
  • How to initialize GUID

    For the details on how to initialize a GUID, check this page http://support.microsoft.com/kb/130869. (definitely we are using a new version compiler! So get to use #include<initguid.h>)

    Summary of a problem I met and finally find the above solution to totally undertand the case:

    Some cpp in our project uses below #include to intialize some GUID:

    #include<XX.\..somename.h>

    #include<XX..\..somename.c> // it includes the CLSID variable like const IID xx = {000..-}

    It's wrong way to initialize a GUID. Because by directly including the CLSID variable, if many cpps need the GUID and #include this way, link error:

    error LNK2005: xx object already defined in xxx.obj.

    Oh, my!

    The correct way to initialize a GUID is to #include<initguid.h> before any #include to use a GUID. By a macro DECLSPEC_SELECTANY keyword is used in the DEFINE_GUID macro, which makes sure that the linker will correctly handle this multiple definition.

    Note more:

    If two cpp in one project #include<test.h>, which includes below:

    #include "StdAfx.h"

    int pp = 100;
    class CTest
    {

    };

    Building the project, we will recevie one link error:

    error LNK2005: "int pp" (?pp@@3HA) already defined

    But the class definition will pass. So the conclusion is: if more than one cpps #include a header file, which happens to define some variable like "int ..", link error will be reported while the class definition is ok to use.

  • 相关阅读:
    React 生命周期
    css 多行文本以...代替
    微信JSSDK配置文件说明
    zepto阻止事件冒泡
    PHP 图片处理PNG颜色丢失
    React 学习笔记(一)
    webpack webpack-dev-server使用指南
    为什么需要使用模块打包工具?
    如何实现微信公户绑定公众号业务
    iOS 手势
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1380324.html
Copyright © 2011-2022 走看看