描述:
我最近看一个COM的简单的小程序
其中有一个头文件,其中这样写道
// GUID of our COM server
_declspec(selectany) GUID CLSID_Mine = { 0xdc186800,
0x657f,
0x11d4,
{ 0xb0, 0xb5, 0x0, 0x50, 0xba, 0xbf, 0xc9, 0x4 }
};
// interface definition
// for sample COM server just replace the uuid of interface and its name
// and add new method prototypes here ..
//
interface __declspec(uuid("F614FB00-6702-11d4-B0B7-0050BABFC904")) ImyInterface : public IUnknown
{
STDMETHOD(Square)(long *pVal)PURE;
STDMETHOD(Cube)(long *pVal)PURE;
};
请问这个CLSID_Mine 是从哪里得来的?
这一串数字{ 0xdc186800,
0x657f,
0x11d4,
{ 0xb0, 0xb5, 0x0, 0x50, 0xba, 0xbf, 0xc9, 0x4 }
};
和这一串数字uuid("F614FB00-6702-11d4-B0B7-0050BABFC904"))
什么关系?
解决方案1:
IDL一般不用看的,你要写COM可以直接用ATL啊。
解决方案2: 都是从IDL文件中经过编译生成的,CLSID_Mine 是在IDL文件中,coclass的属性块中被定义的ID值,uuid(xxxxxxx)是接口的ID值,是在相应的接口的属性中被定义的。还原后很可能是这样:
[
object,
uuid(xxxxxxxxxx), //the guid of the interface
......
]
interface ImyInterface : IUnknown
{
...................
}
[
uuid(xxxxxxxxxx)//the guid of your lib
..........
]
library xxxxlib
{
.............................
[
uuid(xxxxxxxxxx), //the guid of the class
]
coclass Mine
{
[default] ImyInterface
}
}