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