com文件如何查看GUID呢
方法一、
用oleView,找到类,左边选择coclass ...,右边的顶部uuid就是了。或者左边选根部,右侧的下方coclass 上边紧挨的就是uuid了。
方法二、
import library。。。选择文件,生成tlb文件,在里边早const GUID CLSID_myclas=这一行就是了
const GUID LIBID_myTestDllNew = {0xCD09948D, 0xD58D, 0x4A65,{ 0xA9, 0x24, 0x8F,0x8D, 0x84, 0xA2,0x0F, 0xCA} };
const GUID IID__myclass = {0x906A982A, 0xEDA7, 0x439A,{ 0x91, 0xCE, 0xE6,0xC5, 0x52, 0x70,0x6C, 0xAD} };//Interface的GUID叫做IID
const GUID CLSID_myclass = {0xF6295C21, 0xBA09, 0x418A,{ 0xA9, 0x8B, 0xBA,0xA8, 0x7B, 0x50,0x98, 0x3E} }; //coClass的GUID叫做CLSID
调用LoadTypeLib函数,tlibAttr->guid是LIBID_xxxx,并不是CLSID
方法三,看源码c++或delphi
在TMY_liB.pas文件里查找
const
// TypeLibrary Major and minor versions
TMYjorVersion = 1;
TWYinorVersion = 0;
LIBID_TMYTGUID = '{2AD32515-9CA5-4160-B0DF-6A2F4B861475}';
IID_IccMYTGUID = '{64A8DD9D-6ABC-410A-B6FB-E0A36B1BE7F0}';//Dispatch interface for ActiveFormX Control
DIID_IccMYents: TGUID = '{741D7851-089A-4D22-9200-CED8E0AA6223}';//Events interface for ActiveFormX Control
CLASS_ccMYTGUID = '{D44E335B-7A02-4277-910E-6CD641989370}';//这一行就是类、控件的GUID了
方法四,看工程源码 *.ridl文件里 ActiveForm
[
uuid(D44E335B-7A02-4277-910E-6CD641989370),//这个就是了
helpstring("ccEMR Control"),
control
]
GUID赋值二法
1、GUID vGUID = {0xF6295C21, 0xBA09, 0x418A,{ 0xA9, 0x8B, 0xBA,0xA8, 0x7B, 0x50,0x98, 0x3E} };
2、GUID vGUID = Comobj:: StringToGUID("{648A5600-2C6E-101B-82B6-000000000014}");
GUID vGUID = Comobj:: StringToGUID("{F6295C21-BA09-418A-A98B-BAA87B50983E}");
1、类型字符串转换为GUID
ProgIDFromCLSID //objbase.h文件中
ClassIDToProgID //ComObj.hpp
2、GUID转换为类型字符串
CLSIDFromProgID //objbase.h文件中
ProgIDToClassID //ComObj.hpp
D:\Program Files\Borland\CBuilder6\include\guiddef.h
int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) 比较两个GUID是否相等
#include <objbase.h>
#include <OleServer.hpp>
#include <comobj.hpp>
CBuilder6\include\vcl\SysUtils.hpp
这几个转换是必须在注册表regsvr32注册成功后才可以使用!
看源码,感觉comobj的方法是调用了obj的方法,就是封装了一下
{ Convert a string to a GUID }
function StringToGUID(const S: string): TGUID;
begin
OleCheck(CLSIDFromString(PWideChar(WideString(S)), Result));
end;
{ Convert a GUID to a string }
function GUIDToString(const ClassID: TGUID): string;
var
P: PWideChar;
begin
OleCheck(StringFromCLSID(ClassID, P));
Result := P;
CoTaskMemFree(P);
end;
{ Convert a programmatic ID to a class ID }
function ProgIDToClassID(const ProgID: string): TGUID;
begin
OleCheck(CLSIDFromProgID(PWideChar(WideString(ProgID)), Result));
end;
{ Convert a class ID to a programmatic ID }
function ClassIDToProgID(const ClassID: TGUID): string;
var
P: PWideChar;
begin
OleCheck(ProgIDFromCLSID(ClassID, P));
Result := P;
CoTaskMemFree(P);
end;