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.