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.

  • 相关阅读:
    Notification 通知
    首次在MI5手机上看到APP界面 ~
    Installation falied with message Failed to establish session.
    adb.exe 已停止工作
    内容提供器(Content Provider)
    Android 数据存储
    RecyclerView
    UI设计 四种基本布局
    关于Android教学的思考1
    Android 主要控件
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1380324.html
Copyright © 2011-2022 走看看