CLSIDFromProgID、ProgIDFromCLSID、IsEqualCLSID
Uses ComObj, ActiveX;
//COM组件都是用CLSID来标识的,但CLSID不便记忆,通常也用ProgID来标识;
procedure TForm9.BitBtn3Click(Sender: TObject);
var Guid:TGuid;
s:PChar;
begin
//HKEY_CLASSES_ROOT\CLSID:描述了安装在系统中的所有COM组件;
//查注册表HKEY_CLASSES_ROOT\CLSID得知:ProgID "SAPI.SpVoice.1"对应的CLSID为{96749377-3391-11D2-9EE3-00C04F797396};
{CLSIDFromProgID function
Parameters
lpszProgID [in]
A pointer to the ProgID whose CLSID is requested.
lpclsid [out]
Receives a pointer to the retrieved CLSID on return.
Return value
This function can return the following values.
Return code Description
S_OK The CLSID was retrieved successfully.
CO_E_CLASSSTRING The registered CLSID for the ProgID is invalid.
REGDB_E_WRITEREGDB An error occurred writing the CLSID to the registry. See Remarks below.}
if ActiveX.CLSIDFromProgId(PChar('SAPI.SpVoice.1'),Guid)=S_OK then
Memo2.Lines.Add(Format('CLSID:%s',[ComObj.GUIDToString(Guid)]));
{ProgIDFromCLSID function
Parameters
clsid [in]
The CLSID for which the ProgID is to be requested.
lplpszProgID [out]
The address of a pointer variable that receives the ProgID string. The string that represents clsid includes enclosing braces.
Return value
This function can return the following values.
Return code Description
S_OK The ProgID was returned successfully.
REGDB_E_CLASSNOTREG Class not registered in the registry.
REGDB_E_READREGDB There was an error reading from the registry.
Remarks
Call the CLSIDFromProgID function to find the CLSID associated with a given ProgID. Be sure to free the returned ProgID when you are finished with it by calling the CoTaskMemFree function.}
Guid:=ComObj.StringToGUID('{96749377-3391-11D2-9EE3-00C04F797396}');
if ActiveX.ProgIDFromCLSID(Guid,s)=S_OK then
begin
Memo2.Lines.Add(Format('ProgId:%s',[s]));
{CoTaskMemFree function
Parameters
pv [in, optional]
A pointer to the memory block to be freed. If this parameter is NULL, the function has no effect.
Return value
This function does not return a value.}
ActiveX.CoTaskMemFree(s); {用完后必须释放内存}
end;
end;
procedure TForm9.BitBtn4Click(Sender: TObject);
Const Guid1:TGuid='{96749377-3391-11D2-9EE3-00C04F797396}';
Guid2:TGuid='{96749377-3391-11D2-9EE3-00C04F797397}';
begin
{IsEqualCLSID function
Parameters
rclsid1 [in]
The first CLSID.
rclsid2 [in]
The second CLSID.
Return value
If the values are equal, the return value is TRUE. Otherwise, the return value is FALSE.}
if ActiveX.IsEqualCLSID(Guid1,Guid2) then
Memo2.Lines.Strings[0]:='Is Equal.'
else
Memo2.Lines.Strings[0]:='Is Not Equal.';
end;