Hi Kim,
Thanks for the single-most useful reply in a newsgroup ever! :-)
Since, we are already "reinventing the wheel" (surely somebody else
most have made conversion tools ?), I took the liberty to make some
changes (see below),
Thanks again.
Chers,
Morten
-------
// StringToGUID.cpp :
#include "stdafx.h"
#include "stdio.h"
#include <atlbase.h>
int main(int argc, char* argv[])
{
HRESULT hr;
USES_CONVERSION;
if(argc < 2 || argc > 3)
{
printf("Usage: StringToGUID <guid string> [name]\n");
return 1;
}
const char *strGUID = argv[1];
const char* pszName = "<<name>>";
if(argc == 3)
{
pszName = argv[2];
}
GUID guid;
hr = CLSIDFromString(A2OLE(strGUID), &guid);
if(FAILED(hr))
{
printf("Failed to parse GUID string\n");
return hr;
}
printf("static const GUID %s = { // %s\n 0x%08X, 0x%04X, 0x%04X,\n {
0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02x
}\n};\n",
pszName, strGUID, 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]);
return 0;
}
Post by Kim GräsmanHey Morten,
Post by Morten ChristensenYes - strictly speaking I could just call the converter APIs on the
string, but I prefer to have explicit, readable CONSTANTS like this
--
// defguid.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include <atlbase.h>
int main(int argc, char* argv[])
{
HRESULT hr;
USES_CONVERSION;
if(argc < 2 || argc > 3)
{
printf("Usage: defguid <guid string> [name]\n");
return 1;
}
const char* pszName = "unspecified";
if(argc == 3)
{
pszName = argv[2];
}
GUID guid;
hr = CLSIDFromString(A2OLE(argv[1]), &guid);
if(FAILED(hr))
{
printf("Failed to parse GUID string\n");
return hr;
}
printf("DEFINE_GUID(%s, 0x%08X, 0x%04X, 0x%04X, 0x%02X, 0x%02X, 0x%02X,
0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02x);\n",
pszName, 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]);
return 0;
}
--
Hope that helps.