来自:http://blog.sina.com.cn/s/blog_7d1dc9de0100z7hg.html
DEFINE_GUID宏是怎么工作的? DEFINE_GUID(CLSID_MyObject, 这个例子中GUID为0,实际编程中请用Guidgen工具来产生一个GUID,在其中的一个源文件中,在你的头文件前包含initguid.h,如: // Src1.cpp 在没有包含Initguid.h的地方,DEFINE_GUID宏创建外部引用来使用GUID值,在包含Initguid.h的地方,DEFINE_GUID重定义DEFINE_GUID宏以产生GUID的定义。 |
- #ifndef
DEFINE_GUID - #error
initguid: must include objbase.h first. - #endif
- #undef
DEFINE_GUID - #ifdef
_MAC - #define
__based(a) - #endif
- #ifdef
_WIN32 - #define
__based(a) - #endif
- #ifdef
__TURBOC__ - #define
__based(a) - #endif
- #ifndef
_MAC - #define
DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) / -
EXTERN_C const GUID __based(__segname("_CODE")) name / -
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } - #else
- #define
DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) / -
EXTERN_C const GUID name / -
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } - #endif
上面是initguid.h的源代码
The GUID value must be defined exactly once in your project, and the other source files must declare extern references to it。
Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier)
GUID/UUID是通过特定算法产生的一个二进制长度为128位的数字,
在空间上和时间上具有唯一性,保证同一时间不同地方产生的数字不同,
在公元3400年以前产生的UUID/GUID与任何其他产生过的UUIDs/GUIDs都不相同。
在需要GUID的时候,可以完全由算法自动生成,不需要一个权威机构来管理。
GUID的长度固定,并且相对而言较短小,非常适合于排序、标识和存储。