C++ COM编程生成随机GUID值

	char szGuId[64];
	memset(szGuId, 0, 64);

	GUID Guid;
	CoInitialize(NULL);
	if (CoCreateGuid(&Guid) == S_OK)
	{
		wsprintf(szGuId, "{%08X-%04X-%04x-%04X-%06X}",
			Guid.Data1, Guid.Data2, Guid.Data3, 
			Guid.Data4[0],Guid.Data4[1],
			Guid.Data4[2],Guid.Data4[3],
			Guid.Data4[4],Guid.Data4[5],
			Guid.Data4[6],Guid.Data4[7]);
	}
	puts(szGuId);

	CoUninitialize();

你可能感兴趣的:(C/C++)