How to initialize guid

Source: Internet
Author: User

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 variables des the CLSID variable like const IID xx = {000 ..-}

It's wrong way to initialize a guid. Because by directly including the CLSID variable, if your 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 macroDeclspec_selectanyKeyword 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 has des 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.