| 1 | /* $Id: clsid.cpp,v 1.1 2001-04-26 19:26:08 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | *
|
|---|
| 4 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 5 | *
|
|---|
| 6 | */
|
|---|
| 7 | /*
|
|---|
| 8 | * ClassID Manipulation.
|
|---|
| 9 | *
|
|---|
| 10 | * 1/7/99
|
|---|
| 11 | *
|
|---|
| 12 | * Copyright 2000 David J. Raison
|
|---|
| 13 | *
|
|---|
| 14 | * Some portions from Wine Implementation
|
|---|
| 15 | *
|
|---|
| 16 | * Copyright 1995 Martin von Loewis
|
|---|
| 17 | * 1998 Justin Bradford
|
|---|
| 18 | * 1999 Francis Beaudet
|
|---|
| 19 | * 1999 Sylvain St-Germain
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "ole32.h"
|
|---|
| 23 | #include "rpcdce.h"
|
|---|
| 24 |
|
|---|
| 25 | #include "oString.h"
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | // ----------------------------------------------------------------------
|
|---|
| 29 | // CoCreateGuid [OLE32.6]
|
|---|
| 30 | //
|
|---|
| 31 | // Creates a 128bit GUID.
|
|---|
| 32 | // ----------------------------------------------------------------------
|
|---|
| 33 | HRESULT WINAPI CoCreateGuid(
|
|---|
| 34 | GUID * pguid) /* [out] points to the GUID to initialize */
|
|---|
| 35 | {
|
|---|
| 36 | HRESULT hr;
|
|---|
| 37 |
|
|---|
| 38 | dprintf(("OLE32: CoCreateGuid"));
|
|---|
| 39 | hr = UuidCreate(pguid);
|
|---|
| 40 |
|
|---|
| 41 | return hr;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | // ----------------------------------------------------------------------
|
|---|
| 45 | // CLSIDFromProgID16()
|
|---|
| 46 | // ----------------------------------------------------------------------
|
|---|
| 47 | HRESULT WIN32API CLSIDFromProgID16(
|
|---|
| 48 | LPCOLESTR16 lpszProgID, // [in] - UNICODE program id as found in registry
|
|---|
| 49 | LPCLSID pclsid) // [out] - CLSID
|
|---|
| 50 | {
|
|---|
| 51 | // dprintf(("OLE32: CLSIDFromProgID16"));
|
|---|
| 52 |
|
|---|
| 53 | LONG lDataLen = 80;
|
|---|
| 54 | oStringA szKey(lpszProgID);
|
|---|
| 55 | oStringA szCLSID(lDataLen, 1);
|
|---|
| 56 | HKEY hKey;
|
|---|
| 57 | HRESULT rc;
|
|---|
| 58 |
|
|---|
| 59 | // Create the registry lookup string...
|
|---|
| 60 | szKey += "\\CLSID";
|
|---|
| 61 |
|
|---|
| 62 | // Try to open the key in the registry...
|
|---|
| 63 | rc = RegOpenKeyA(HKEY_CLASSES_ROOT, szKey, &hKey);
|
|---|
| 64 | if (rc != 0)
|
|---|
| 65 | return OLE_ERROR_GENERIC;
|
|---|
| 66 |
|
|---|
| 67 | // Now get the data from the _default_ entry on this key...
|
|---|
| 68 | rc = RegQueryValueA(hKey, NULL, szCLSID, &lDataLen);
|
|---|
| 69 | RegCloseKey(hKey);
|
|---|
| 70 | if (rc != 0)
|
|---|
| 71 | return OLE_ERROR_GENERIC;
|
|---|
| 72 |
|
|---|
| 73 | // Now convert from a string to a UUID
|
|---|
| 74 | return CLSIDFromString16(szCLSID, pclsid);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // ----------------------------------------------------------------------
|
|---|
| 78 | // CLSIDFromProgID()
|
|---|
| 79 | // ----------------------------------------------------------------------
|
|---|
| 80 | HRESULT WIN32API CLSIDFromProgID(
|
|---|
| 81 | LPCOLESTR lpszProgID, // [in] - UNICODE program id as found in registry
|
|---|
| 82 | LPCLSID pclsid) // [out] - CLSID
|
|---|
| 83 | {
|
|---|
| 84 | // dprintf(("OLE32: CLSIDFromProgID"));
|
|---|
| 85 |
|
|---|
| 86 | LONG lDataLen = 80;
|
|---|
| 87 | oStringW szKey(lpszProgID);
|
|---|
| 88 | oStringW szCLSID(lDataLen, 1);
|
|---|
| 89 | HKEY hKey;
|
|---|
| 90 | HRESULT rc;
|
|---|
| 91 |
|
|---|
| 92 | // Create the registry lookup string...
|
|---|
| 93 | szKey += L"\\CLSID";
|
|---|
| 94 |
|
|---|
| 95 | // Try to open the key in the registry...
|
|---|
| 96 | rc = RegOpenKeyW(HKEY_CLASSES_ROOT, szKey, &hKey);
|
|---|
| 97 | if (rc != 0)
|
|---|
| 98 | return OLE_ERROR_GENERIC;
|
|---|
| 99 |
|
|---|
| 100 | // Now get the data from the _default_ entry on this key...
|
|---|
| 101 | rc = RegQueryValueW(hKey, NULL, szCLSID, &lDataLen);
|
|---|
| 102 | RegCloseKey(hKey);
|
|---|
| 103 | if (rc != 0)
|
|---|
| 104 | return OLE_ERROR_GENERIC;
|
|---|
| 105 |
|
|---|
| 106 | // Now convert from a string to a UUID
|
|---|
| 107 | return CLSIDFromString(szCLSID, pclsid);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // ----------------------------------------------------------------------
|
|---|
| 111 | // IIDFromString
|
|---|
| 112 | // ----------------------------------------------------------------------
|
|---|
| 113 | HRESULT WIN32API IIDFromString(LPSTR lpsz, LPIID lpiid)
|
|---|
| 114 | {
|
|---|
| 115 | // dprintf(("OLE32: IIDFromString"));
|
|---|
| 116 | return CLSIDFromString((LPCOLESTR)lpsz, (LPCLSID)lpiid);
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | // ----------------------------------------------------------------------
|
|---|
| 121 | // CLSIDFromStringA()
|
|---|
| 122 | // @@@PH: this is not a WINE API, but a replacement for CLSIDFromString16
|
|---|
| 123 | // which used to accept ASCII strings instead of OLE strings
|
|---|
| 124 | // ----------------------------------------------------------------------
|
|---|
| 125 |
|
|---|
| 126 | HRESULT WIN32API CLSIDFromStringA(
|
|---|
| 127 | LPCSTR lpsz, // [in] - ASCII string CLSID
|
|---|
| 128 | LPCLSID pclsid) // [out] - Binary CLSID
|
|---|
| 129 | {
|
|---|
| 130 | return CLSIDFromString16(lpsz, pclsid);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 | // ----------------------------------------------------------------------
|
|---|
| 135 | // CLSIDFromString16()
|
|---|
| 136 | // ----------------------------------------------------------------------
|
|---|
| 137 | HRESULT WIN32API CLSIDFromString16(
|
|---|
| 138 | LPCOLESTR16 lpsz, // [in] - Unicode string CLSID
|
|---|
| 139 | LPCLSID pclsid) // [out] - Binary CLSID
|
|---|
| 140 | {
|
|---|
| 141 | // dprintf(("OLE32: CLSIDFromString16"));
|
|---|
| 142 |
|
|---|
| 143 | // Convert to binary CLSID
|
|---|
| 144 | char *s = (char *) lpsz;
|
|---|
| 145 | char *p;
|
|---|
| 146 | int i;
|
|---|
| 147 | char table[256];
|
|---|
| 148 |
|
|---|
| 149 | /* quick lookup table */
|
|---|
| 150 | memset(table, 0, 256);
|
|---|
| 151 |
|
|---|
| 152 | for (i = 0; i < 10; i++)
|
|---|
| 153 | {
|
|---|
| 154 | table['0' + i] = i;
|
|---|
| 155 | }
|
|---|
| 156 | for (i = 0; i < 6; i++)
|
|---|
| 157 | {
|
|---|
| 158 | table['A' + i] = i+10;
|
|---|
| 159 | table['a' + i] = i+10;
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
|
|---|
| 163 |
|
|---|
| 164 | if (lstrlenA(lpsz) != 38)
|
|---|
| 165 | return OLE_ERROR_OBJECT;
|
|---|
| 166 |
|
|---|
| 167 | p = (char *) pclsid;
|
|---|
| 168 |
|
|---|
| 169 | s++; /* skip leading brace */
|
|---|
| 170 | for (i = 0; i < 4; i++)
|
|---|
| 171 | {
|
|---|
| 172 | p[3 - i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 173 | s += 2;
|
|---|
| 174 | }
|
|---|
| 175 | p += 4;
|
|---|
| 176 | s++; /* skip - */
|
|---|
| 177 |
|
|---|
| 178 | for (i = 0; i < 2; i++)
|
|---|
| 179 | {
|
|---|
| 180 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 181 | s += 2;
|
|---|
| 182 | }
|
|---|
| 183 | p += 2;
|
|---|
| 184 | s++; /* skip - */
|
|---|
| 185 |
|
|---|
| 186 | for (i = 0; i < 2; i++)
|
|---|
| 187 | {
|
|---|
| 188 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 189 | s += 2;
|
|---|
| 190 | }
|
|---|
| 191 | p += 2;
|
|---|
| 192 | s++; /* skip - */
|
|---|
| 193 |
|
|---|
| 194 | /* these are just sequential bytes */
|
|---|
| 195 | for (i = 0; i < 2; i++)
|
|---|
| 196 | {
|
|---|
| 197 | *p++ = table[*s]<<4 | table[*(s+1)];
|
|---|
| 198 | s += 2;
|
|---|
| 199 | }
|
|---|
| 200 | s++; /* skip - */
|
|---|
| 201 |
|
|---|
| 202 | for (i = 0; i < 6; i++)
|
|---|
| 203 | {
|
|---|
| 204 | *p++ = table[*s]<<4 | table[*(s+1)];
|
|---|
| 205 | s += 2;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | return S_OK;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | // ----------------------------------------------------------------------
|
|---|
| 212 | // CLSIDFromString()
|
|---|
| 213 | // ----------------------------------------------------------------------
|
|---|
| 214 | HRESULT WIN32API CLSIDFromString(
|
|---|
| 215 | LPCOLESTR lpsz, // [in] - Unicode string CLSID
|
|---|
| 216 | LPCLSID pclsid) // [out] - Binary CLSID
|
|---|
| 217 | {
|
|---|
| 218 | // dprintf(("OLE32: CLSIDFromString"));
|
|---|
| 219 |
|
|---|
| 220 | oStringA tClsId(lpsz);
|
|---|
| 221 |
|
|---|
| 222 | return CLSIDFromString16(tClsId, pclsid);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | // ----------------------------------------------------------------------
|
|---|
| 226 | // WINE_StringFromCLSID
|
|---|
| 227 | // ----------------------------------------------------------------------
|
|---|
| 228 | HRESULT WIN32API WINE_StringFromCLSID(const CLSID *rclsid, LPSTR idstr)
|
|---|
| 229 | {
|
|---|
| 230 | // dprintf(("OLE32: WINE_StringFromCLSID"));
|
|---|
| 231 |
|
|---|
| 232 | if (rclsid == NULL)
|
|---|
| 233 | {
|
|---|
| 234 | dprintf((" clsid: (NULL)"));
|
|---|
| 235 | *idstr = 0;
|
|---|
| 236 | return E_FAIL;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | // Setup new string...
|
|---|
| 240 | sprintf(idstr, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
|
|---|
| 241 | rclsid->Data1,
|
|---|
| 242 | rclsid->Data2,
|
|---|
| 243 | rclsid->Data3,
|
|---|
| 244 | rclsid->Data4[0],
|
|---|
| 245 | rclsid->Data4[1],
|
|---|
| 246 | rclsid->Data4[2],
|
|---|
| 247 | rclsid->Data4[3],
|
|---|
| 248 | rclsid->Data4[4],
|
|---|
| 249 | rclsid->Data4[5],
|
|---|
| 250 | rclsid->Data4[6],
|
|---|
| 251 | rclsid->Data4[7]);
|
|---|
| 252 |
|
|---|
| 253 | // dprintf((" clsid: %s", idstr));
|
|---|
| 254 |
|
|---|
| 255 | return OLE_OK;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | // ----------------------------------------------------------------------
|
|---|
| 259 | // StringFromCLSID
|
|---|
| 260 | // Memory allocated here on behalf of application should be freed using CoTaskMemFree()
|
|---|
| 261 | // ----------------------------------------------------------------------
|
|---|
| 262 | HRESULT WIN32API StringFromCLSID(REFCLSID rclsid, LPOLESTR *ppsz)
|
|---|
| 263 | {
|
|---|
| 264 | char tmp[50];
|
|---|
| 265 | LPWSTR szclsid;
|
|---|
| 266 | size_t strLen;
|
|---|
| 267 |
|
|---|
| 268 | // dprintf(("OLE32: StringFromCLSID"));
|
|---|
| 269 |
|
|---|
| 270 | // Setup new string...
|
|---|
| 271 | WINE_StringFromCLSID(rclsid, tmp);
|
|---|
| 272 |
|
|---|
| 273 | strLen = strlen(tmp);
|
|---|
| 274 |
|
|---|
| 275 | // Grab buffer for string...
|
|---|
| 276 | szclsid = (LPWSTR)CoTaskMemAlloc((strLen + 1) * sizeof(WCHAR));
|
|---|
| 277 |
|
|---|
| 278 | AsciiToUnicode(tmp, szclsid);
|
|---|
| 279 |
|
|---|
| 280 | *ppsz = (LPOLESTR)szclsid;
|
|---|
| 281 |
|
|---|
| 282 | return S_OK;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | // ----------------------------------------------------------------------
|
|---|
| 286 | // StringFromIID
|
|---|
| 287 | // Memory allocated here on behalf of application should be freed using CoTaskMemFree()
|
|---|
| 288 | // ----------------------------------------------------------------------
|
|---|
| 289 | HRESULT WIN32API StringFromIID(REFIID riid, LPOLESTR *ppsz)
|
|---|
| 290 | {
|
|---|
| 291 | char tmp[50];
|
|---|
| 292 | LPWSTR sziid;
|
|---|
| 293 | size_t strLen;
|
|---|
| 294 |
|
|---|
| 295 | // dprintf(("OLE32: StringFromIID"));
|
|---|
| 296 |
|
|---|
| 297 | // Setup new string...
|
|---|
| 298 | WINE_StringFromCLSID(riid, tmp);
|
|---|
| 299 |
|
|---|
| 300 | strLen = strlen(tmp);
|
|---|
| 301 |
|
|---|
| 302 | // Grab buffer for string...
|
|---|
| 303 | sziid = (LPWSTR)CoTaskMemAlloc((strLen + 1) * sizeof(WCHAR));
|
|---|
| 304 |
|
|---|
| 305 | AsciiToUnicode(tmp, sziid);
|
|---|
| 306 |
|
|---|
| 307 | *ppsz = (LPOLESTR)sziid;
|
|---|
| 308 |
|
|---|
| 309 | return S_OK;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | // ----------------------------------------------------------------------
|
|---|
| 313 | // StringFromGUID2
|
|---|
| 314 | // ----------------------------------------------------------------------
|
|---|
| 315 | int WIN32API StringFromGUID2(REFGUID rguid, LPOLESTR lpsz, int cbMax)
|
|---|
| 316 | {
|
|---|
| 317 | // NB cbMax is a CHARACTER count not a BYTE count... :-)
|
|---|
| 318 | char tmp[50];
|
|---|
| 319 | size_t strLen;
|
|---|
| 320 |
|
|---|
| 321 | // Setup new string...
|
|---|
| 322 | WINE_StringFromCLSID(rguid, tmp);
|
|---|
| 323 |
|
|---|
| 324 | strLen = (strlen(tmp) + 1);
|
|---|
| 325 | if (strLen > cbMax)
|
|---|
| 326 | strLen = cbMax;
|
|---|
| 327 |
|
|---|
| 328 | AsciiToUnicodeN(tmp, lpsz, strLen);
|
|---|
| 329 |
|
|---|
| 330 | return strLen; // Num CHARACTERS including 0 terminator
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | // ----------------------------------------------------------------------
|
|---|
| 334 | // CONCRETE_IsEqualGUID
|
|---|
| 335 | // ----------------------------------------------------------------------
|
|---|
| 336 | int WIN32API CONCRETE_IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
|
|---|
| 337 | {
|
|---|
| 338 | return IsEqualGUID(rguid1, rguid2);
|
|---|
| 339 | }
|
|---|
| 340 |
|
|---|
| 341 | // ----------------------------------------------------------------------
|
|---|
| 342 | // ReadClassStm
|
|---|
| 343 | // ----------------------------------------------------------------------
|
|---|
| 344 | HRESULT WIN32API ReadClassStm(IStream *pStm, CLSID *rclsid)
|
|---|
| 345 | {
|
|---|
| 346 | ULONG nbByte;
|
|---|
| 347 | HRESULT res;
|
|---|
| 348 |
|
|---|
| 349 | dprintf(("OLE32: ReadClassStm"));
|
|---|
| 350 |
|
|---|
| 351 | if (rclsid == NULL)
|
|---|
| 352 | return E_INVALIDARG;
|
|---|
| 353 |
|
|---|
| 354 | res = IStream_Read(pStm,(void*)rclsid,sizeof(CLSID),&nbByte);
|
|---|
| 355 |
|
|---|
| 356 | if (FAILED(res))
|
|---|
| 357 | return res;
|
|---|
| 358 |
|
|---|
| 359 | if (nbByte != sizeof(CLSID))
|
|---|
| 360 | return S_FALSE;
|
|---|
| 361 |
|
|---|
| 362 | return S_OK;
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | // ----------------------------------------------------------------------
|
|---|
| 366 | // WriteClassStm
|
|---|
| 367 | // ----------------------------------------------------------------------
|
|---|
| 368 | HRESULT WIN32API WriteClassStm(IStream *pStm, REFCLSID rclsid)
|
|---|
| 369 | {
|
|---|
| 370 | dprintf(("OLE32: WriteClassStm"));
|
|---|
| 371 |
|
|---|
| 372 | if (rclsid == NULL)
|
|---|
| 373 | return E_INVALIDARG;
|
|---|
| 374 |
|
|---|
| 375 | return IStream_Write(pStm, rclsid, sizeof(CLSID), NULL);
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | // ----------------------------------------------------------------------
|
|---|
| 379 | // ProgIDFromCLSID
|
|---|
| 380 | // ----------------------------------------------------------------------
|
|---|
| 381 | HRESULT WIN32API ProgIDFromCLSID(REFCLSID clsid, LPOLESTR *lplpszProgID)
|
|---|
| 382 | {
|
|---|
| 383 | oStringA tClsId(clsid);
|
|---|
| 384 | oStringA szKey("CLSID\\");
|
|---|
| 385 | LONG lDataLen = 255;
|
|---|
| 386 | oStringA szProgID(lDataLen, 1);
|
|---|
| 387 | HKEY hKey;
|
|---|
| 388 | HRESULT rc;
|
|---|
| 389 | LPOLESTR tmp;
|
|---|
| 390 | LPMALLOC pMllc;
|
|---|
| 391 |
|
|---|
| 392 | // dprintf(("OLE32: ProgIDFromCLSID"));
|
|---|
| 393 | // dprintf((" clsid = %s", (char *)tClsId));
|
|---|
| 394 |
|
|---|
| 395 | szKey += tClsId + "\\ProgID";
|
|---|
| 396 |
|
|---|
| 397 | // Open key...
|
|---|
| 398 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, szKey, &hKey))
|
|---|
| 399 | return REGDB_E_CLASSNOTREG;
|
|---|
| 400 |
|
|---|
| 401 | // Get default string from the key...
|
|---|
| 402 | rc = RegQueryValueA(hKey, NULL, szProgID, &lDataLen);
|
|---|
| 403 | RegCloseKey(hKey);
|
|---|
| 404 | if (rc != 0)
|
|---|
| 405 | return REGDB_E_CLASSNOTREG;
|
|---|
| 406 |
|
|---|
| 407 | if (CoGetMalloc(0, &pMllc)) // Singleton instance, no need to release
|
|---|
| 408 | return E_OUTOFMEMORY;
|
|---|
| 409 |
|
|---|
| 410 | tmp = (LPOLESTR)IMalloc_Alloc(pMllc, (strlen(szProgID) + 1) * 2);
|
|---|
| 411 | if (tmp == NULL)
|
|---|
| 412 | return E_OUTOFMEMORY;
|
|---|
| 413 |
|
|---|
| 414 | AsciiToUnicode(szProgID, tmp);
|
|---|
| 415 | *lplpszProgID = tmp;
|
|---|
| 416 |
|
|---|
| 417 | return S_OK;
|
|---|
| 418 | }
|
|---|