GUID, UUID, CLSID, and IID in COM

Source: Internet
Author: User
GUID, UUID, CLSID, and IID in COM

(15:56:13)

ReprintedBytes
Tags:

It
 

(I have read the article "GUID... COM" on the Internet today, so it is recorded .)
When Microsoft designed the com specification, there were two options to ensure that the com component designed by the user could be globally unique:

The first is to establish a management organization using the same management method as the Internet address. If you want to develop a COM component, you need to apply to the organization and pay a certain fee.

The second method is to create an algorithm that generates a globally unique COM component identifier each time.

The first method is too inconvenient for users. Microsoft adopted the second method and invented an algorithm, which uses GUID (Globally
Unique
Identifiers) to identify the COM component. GUID is a 128-bit long number, which is generally expressed in hexadecimal notation. The core idea of an algorithm is to combine the machine's Nic, local time, and a random number to generate a GUID. Theoretically, if a machine generates 10000000 guids per second, it can ensure (in probability) that there will be no duplicates in 3240.

Example of GUID:
54BF6567--1007--11D1--B0AA--444553540000


HKEY_CLASSES_ROOT \ CLSID \ {002B9E07-2E10-438F-AF1E-40E6A96F1EE4}

In Microsoft's COM, GUID is the same as UUID, CLSID, and IID, but their meanings are different:

UUID
: COM

CLSID
: Indicates the class in the COM component.

IID
: Indicates the interface in the COM component.

In a program, the path strings of the processing program corresponding to the actual object data are often different. For example, if some D disks are attached to drive C, Microsoft has come up with a solution, that is, instead of using a direct path representation method
The CLSID method indirectly describes the processing path of these object data.

CLSID
It is actually a number. The CLSID structure is defined as follows:

Typedef
Struct _ GUID {
DWORD Data1 ;//
Random Number
WORD Data2; // time-related
WORD Data3; // time-related
BYTE Data4 [8]; // related to the MAC of the NIC
} GUID;

Typedef
Guid clsid; // component ID
Typedef GUID
IID; // Interface ID
# Define
REFCLSID const CLSID &

//
Common declarations and Assignment Methods
CLSID CLSID_Excel =
{0x00024500,0 x random, 0x0000, {0xC0, 0x00,0x00,0x00,0x00,0x00,0x00,0x46 }};
Struct
_ Declspec (uuid ("00024500-0000-0000-C000-000000000046") CLSID_Excel;
Class
DECLSPEC_UUID ("00024500-0000-0000-C000-000000000046") CLSID_Excel;
// Indicates the method in the registry.
{00024500-0000-0000-C000-000000000046}

If you use the development environment to write component programs, IDE will automatically generate
CLSID;

Functions available
CoCreateGuid () generates CLSID;

Use the "vc directory \ Common \ Tools \ GuidGen.exe" tool to generate a GUID

Each COM component must specify
CLSID. duplicate names are not allowed. It uses 16 bytes, which means it is "impossible" to ensure the repetition probability. However, for ease of use, Microsoft also supports another string name method called
ProgID .. Since CLSID and ProgID are actually two different representations of a concept, we can use either of them in the program.
The conversion method and related functions between CLSID and ProgID are as follows:

Function
Function Description
CLSIDFromProgID (), CLSIDFromProgIDEx ()
Obtain CLSID from ProgID. There's nothing to say. You can write it yourself. check Registry Bay.
ProgIDFromCLSID () is obtained by CLSID ProgID. After the caller completes use, the ProgID must be released.
Memory (note 5)
CoCreateGuid () randomly generates a GUID
IsEqualGUID (), IsEqualCLSID (), IsEqualIID ()
Compare whether two IDs are equal
StringFromCLSID (), StringFromGUID2 (), StringFromIID ()
CLSID and IID get the CLSID-style string in the registry. Pay attention to release the memory.

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.