在公元3400年以前产生的UUID/GUID与任何其他产生过的UUIDs/GUIDs都不 相同。
GUID不重复的特性倒是可以用了做随机字符
比如把窗口类名和标题名都用GUID,那FindWindow就无效了.
使用CoCreateGuid函数,你需要
#include <ObjBase.h>
#pragma comment(lib,"ole32.lib")
比如用GUID做随机标题
//main random title
WCHAR *szMainTitle=new WCHAR[MAX_STRING_LENGTH];
if (NULL==szMainTitle)
{
return -1;
}
ZeroMemory(szMainTitle,sizeof(szMainTitle));
if (!MyGetGUID(szMainTitle))
{
wcscpy(szMainTitle,_T("Ares"));
}
.............
if (NULL!=szMainTitle)
{
delete szMainTitle;
szMainTitle=NULL;
}
GUID不重复的特性倒是可以用了做随机字符
比如把窗口类名和标题名都用GUID,那FindWindow就无效了.
使用CoCreateGuid函数,你需要
#include <ObjBase.h>
#pragma comment(lib,"ole32.lib")
//Get the GUID,
//cdutboy@gmail.com
BOOL MyGetGUID(__out WCHAR* szGUID)
{
CoInitialize(NULL);
BOOL bReturnFlag=FALSE;
GUID stMyGuid={0};
if (S_OK == CoCreateGuid(&stMyGuid))
{
bReturnFlag=TRUE;
wsprintfW(szGUID,_T("%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X"),\
stMyGuid.Data1,stMyGuid.Data2,stMyGuid.Data3,\
stMyGuid.Data4[0],stMyGuid.Data4[1],stMyGuid.Data4[2],stMyGuid.Data4[3],\
stMyGuid.Data4[4],stMyGuid.Data4[5],stMyGuid.Data4[6],stMyGuid.Data4[7]);
}
CoUninitialize();
return bReturnFlag;
}
//cdutboy@gmail.com
BOOL MyGetGUID(__out WCHAR* szGUID)
{
CoInitialize(NULL);
BOOL bReturnFlag=FALSE;
GUID stMyGuid={0};
if (S_OK == CoCreateGuid(&stMyGuid))
{
bReturnFlag=TRUE;
wsprintfW(szGUID,_T("%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X"),\
stMyGuid.Data1,stMyGuid.Data2,stMyGuid.Data3,\
stMyGuid.Data4[0],stMyGuid.Data4[1],stMyGuid.Data4[2],stMyGuid.Data4[3],\
stMyGuid.Data4[4],stMyGuid.Data4[5],stMyGuid.Data4[6],stMyGuid.Data4[7]);
}
CoUninitialize();
return bReturnFlag;
}
比如用GUID做随机标题
//main random title
WCHAR *szMainTitle=new WCHAR[MAX_STRING_LENGTH];
if (NULL==szMainTitle)
{
return -1;
}
ZeroMemory(szMainTitle,sizeof(szMainTitle));
if (!MyGetGUID(szMainTitle))
{
wcscpy(szMainTitle,_T("Ares"));
}
.............
if (NULL!=szMainTitle)
{
delete szMainTitle;
szMainTitle=NULL;
}