#include <windows.h>
#include <tchar.h>
#include <string>
int WINAPI _tWinMain ( HINSTANCE,
HINSTANCE,
_TCHAR *,
int )
{
HRESULT hResult;
GUID guid;
memset ( &guid, 0, sizeof ( GUID ) );
hResult = CoCreateGuid ( &guid );
if ( SUCCEEDED ( hResult ) )
{
LPOLESTR pOleStr;
hResult = StringFromIID ( guid, &pOleStr );
if ( SUCCEEDED ( hResult ) )
{
std::basic_string < _TCHAR > strResult;
#ifdef _UNICODE
strResult = pOleStr;
#else
UINT nSize = wcstombs ( NULL, pOleStr, 0 );
char *pszBuf = new char[ nSize + 1 ];
memset ( pszBuf, 0, nSize + 1 );
wcstombs ( pszBuf, pOleStr, nSize );
strResult = pszBuf;
delete[] pszBuf;
#endif
CoTaskMemFree ( pOleStr );
MessageBox ( NULL,
strResult.c_str (),
_TEXT ( "生成した GUID の確認" ),
MB_OK );
}
}
return 0;
}
|