Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CLSID? Is it a GUID?

I want to know what is exactly CLSID data type, as it is used in C++, and I want to use it in delphi.

  • what is CLSID?
like image 508
Mahmoud Almontasser Avatar asked Oct 19 '13 21:10

Mahmoud Almontasser


1 Answers

A CLSID is a GUID that identifies a COM object. In order to instantiate a registered COM object, you need to know its CLSID.

Typically in Delphi you would be calling CoCreateInstance. You simply call the function and pass a CLSID. The declaration of CoCreateInstance declares the class ID parameter as having type TCLSID which is a simple alias of TGUID. So pass one of those.

Here are the declarations, as lifted from the Delphi source:

type
  TCLSID = TGUID;

function CoCreateInstance(const clsid: TCLSID; unkOuter: IUnknown;
  dwClsContext: Longint; const iid: TIID; out pv): HResult; stdcall;

An example of a call to CoCreateInstance, taken from my code base:

const
  CLSID_WICImagingFactory: TGUID = '{CACAF262-9370-4615-A13B-9F5539DA4C0A}';

if not Succeeded(CoCreateInstance(CLSID_WICImagingFactory, ...)) then
  ...

You will likely be creating a different interface, and so will need to substitute the appropriate CLSID for that interface.

There is one other little trick that is worth knowing about. If you pass an interface type as a parameter of type TGUID, and that interface type has a GUID, then the compiler will substitute the GUID for you. So the above code could equally well be written:

type
  IWICImagingFactory = interface
    // this is the GUID of the interface, the CLSID
    [{ec5ec8a9-c395-4314-9c77-54d7a935ff70}] 
    ....
  end;

....

if not Succeeded(CoCreateInstance(IWICImagingFactory, ...)) then
  ...
like image 93
David Heffernan Avatar answered Sep 20 '22 01:09

David Heffernan