GUID to String, String to GUID
Tuesday, February 15, 2011 6:39:31 PM
I have spend measureless amount of time getting this to work. Hopefully it will help.
What snippet does:
What snippet does:
- Creates new GUID from user defined string.
- Creates string from GUID and prints it out.
CLSID g1;
wchar_t buf[39] = {0};
char print[39] = {0};
HRESULT hr = CLSIDFromString((LPOLESTR) L"{7D17733C-46C5-4F80-8D32-8754DCBD7295}", &g1);
if (hr != NOERROR) {
cout << "Error:";
switch (hr) {
case CO_E_CLASSSTRING: cout << "CO_E_CLASSSTRING" << endl; break;
case REGDB_E_CLASSNOTREG: cout << "REGDB_E_CLASSNOTREG" << endl; break;
case REGDB_E_READREGDB: cout << "REGDB_E_READREGDB" << endl; break;
}
system("pause");
return -1;
}
StringFromGUID2(g1, buf, 39);
wcstombs(print, buf, 39);
cout << print << endl;
). How to be more secured?





