1. 程式人生 > >C++中GUID轉字串

C++中GUID轉字串

使用StringFromGUID2轉換GUID為字串

#include "stdafx.h"
#include <stdlib.h>
#include <objbase.h>

int _tmain(int argc, _TCHAR* argv[])
{

	GUID guid = { 0 };
	if (CoCreateGuid(&guid) == S_OK)
	{
		wchar_t test[48] = { 0 };
		StringFromGUID2(guid, test, sizeof(test));
		wprintf(test);
	}
	system("pause");
	return 0;
}

或者使用StringFromCLSID函式

#include "stdafx.h"
#include <combaseapi.h>


int _tmain(int argc, _TCHAR* argv[])
{
	GUID guid = { 0 };
	CoCreateGuid(&guid);
	LPOLESTR s_guid[40] = { 0 };
	StringFromCLSID(guid,s_guid);
	return 0;
}