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;
}

猜你喜欢

转载自blog.csdn.net/cssxn/article/details/83784283