Changeset 5280 for trunk/src/ole32/ole2.cpp
- Timestamp:
- Feb 28, 2001, 9:30:22 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ole32/ole2.cpp
r5274 r5280 1 /* $Id: ole2.cpp,v 1. 4 2001-02-27 22:25:54 hughExp $ */2 /* 3 * 1 /* $Id: ole2.cpp,v 1.5 2001-02-28 20:30:22 sandervl Exp $ */ 2 /* 3 * 4 4 * Project Odin Software License can be found in LICENSE.TXT 5 * 5 * 6 6 */ 7 /* 7 /* 8 8 * OLE functions. 9 * 9 * 10 10 * 2/9/99 11 * 11 * 12 12 * Copyright 1999 David J. Raison 13 13 * … … 15 15 * Copyright 1995 Martin von Loewis 16 16 * Copyright 1999 Francis Beaudet 17 * Copyright 1999 Noel Borthwick 17 * Copyright 1999 Noel Borthwick 18 18 */ 19 19 … … 24 24 #include <assert.h> 25 25 26 // ====================================================================== 26 // ====================================================================== 27 27 // Local Data 28 // ====================================================================== 28 // ====================================================================== 29 29 30 30 /* … … 35 35 36 36 37 // ====================================================================== 37 // ====================================================================== 38 38 // Prototypes. 39 // ====================================================================== 39 // ====================================================================== 40 40 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue); 41 41 42 42 // These are the prototypes of the utility methods used to manage a shared menu 43 extern voidOLEMenu_Initialize();44 extern voidOLEMenu_UnInitialize();43 extern void OLEMenu_Initialize(); 44 extern void OLEMenu_UnInitialize(); 45 45 46 46 // These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c) 47 extern voidOLEClipbrd_UnInitialize();48 extern voidOLEClipbrd_Initialize();47 extern void OLEClipbrd_UnInitialize(); 48 extern void OLEClipbrd_Initialize(); 49 49 50 50 // These are the prototypes of the utility methods used for OLE Drag n Drop 51 extern voidOLEDD_Initialize();52 extern voidOLEDD_UnInitialize();53 54 // ====================================================================== 51 extern void OLEDD_Initialize(); 52 extern void OLEDD_UnInitialize(); 53 54 // ====================================================================== 55 55 // Public API's 56 // ====================================================================== 56 // ====================================================================== 57 57 58 58 // ---------------------------------------------------------------------- … … 77 77 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 78 78 if (FAILED(hr)) 79 return hr; 79 return hr; 80 80 81 81 // Then, it has to initialize the OLE specific modules. … … 87 87 if (++OLE_moduleLockCount == 1) 88 88 { 89 90 91 92 93 94 95 96 97 98 89 dprintf((" First time through - Initializing")); 90 91 // OLE Clipboard 92 OLEClipbrd_Initialize(); 93 94 // Drag and Drop 95 OLEDD_Initialize(); 96 97 // OLE shared menu 98 OLEMenu_Initialize(); 99 99 } 100 100 … … 121 121 if (--OLE_moduleLockCount == 0) 122 122 { 123 124 125 126 127 128 129 130 131 132 123 dprintf((" no more references - Terminating")); 124 125 // OLE Clipboard 126 OLEClipbrd_UnInitialize(); 127 128 // Drag and Drop 129 OLEDD_UnInitialize(); 130 131 // OLE shared menu 132 OLEMenu_UnInitialize(); 133 133 } 134 134 … … 146 146 // ---------------------------------------------------------------------- 147 147 HRESULT WIN32API OleRegGetUserType 148 (REFCLSID clsid,149 DWORD 150 LPOLESTR * 151 152 { 153 oStringA 154 DWORD 155 DWORD 156 HKEY 157 LONG 158 LPSTR 148 (REFCLSID clsid, 149 DWORD dwFormOfType, 150 LPOLESTR * pszUserType) 151 152 { 153 oStringA tCLSID; 154 DWORD dwKeyType; 155 DWORD cbData; 156 HKEY clsidKey; 157 LONG hres; 158 LPSTR buffer; 159 159 160 160 dprintf(("OLE32: OleRegGetUserType")); … … 165 165 tCLSID = "CLSID\\"; 166 166 tCLSID += clsid; 167 tCLSID += " }";167 tCLSID += "\\"; 168 168 169 169 // Open the class id Key 170 170 hres = RegOpenKeyA(HKEY_CLASSES_ROOT, tCLSID, &clsidKey); 171 171 if (hres != ERROR_SUCCESS) 172 172 return REGDB_E_CLASSNOTREG; 173 173 174 174 // Retrieve the size of the name string. … … 177 177 if (hres != ERROR_SUCCESS) 178 178 { 179 180 179 RegCloseKey(clsidKey); 180 return REGDB_E_READREGDB; 181 181 } 182 182 … … 186 186 if (buffer == NULL) 187 187 { 188 189 188 RegCloseKey(clsidKey); 189 return E_OUTOFMEMORY; 190 190 } 191 191 … … 194 194 if (hres != ERROR_SUCCESS) 195 195 { 196 197 196 HeapFree(GetProcessHeap(), 0, buffer); 197 return REGDB_E_READREGDB; 198 198 } 199 199 … … 203 203 if (*pszUserType == NULL) 204 204 { 205 206 205 HeapFree(GetProcessHeap(), 0, buffer); 206 return E_OUTOFMEMORY; 207 207 } 208 208 … … 218 218 // ---------------------------------------------------------------------- 219 219 HRESULT WIN32API OleRegGetMiscStatus 220 (REFCLSID 221 DWORD 222 DWORD * 223 { 224 oStringA 225 HKEY 226 HKEY 227 HKEY 228 LONG 220 (REFCLSID clsid, 221 DWORD dwAspect, 222 DWORD * pdwStatus) 223 { 224 oStringA tStr; 225 HKEY clsidKey; 226 HKEY miscStatusKey; 227 HKEY aspectKey; 228 LONG result; 229 229 230 230 dprintf(("OLE32: OleRegGetMiscStatus")); … … 236 236 tStr = "CLSID\\"; 237 237 tStr += clsid; 238 tStr += " }";238 tStr += "\\"; 239 239 dprintf((" Key : %s", (char *)tStr)); 240 240 … … 243 243 244 244 if (result != ERROR_SUCCESS) 245 245 return REGDB_E_CLASSNOTREG; 246 246 247 247 // Get the MiscStatus … … 250 250 if (result != ERROR_SUCCESS) 251 251 { 252 253 252 RegCloseKey(clsidKey); 253 return REGDB_E_READREGDB; 254 254 } 255 255 … … 258 258 259 259 // Open the key specific to the requested aspect. 260 oStringA 260 oStringA tKey(dwAspect); 261 261 dprintf((" Aspect: %s", (char *)tKey)); 262 262 … … 265 265 if (result == ERROR_SUCCESS) 266 266 { 267 268 267 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus); 268 RegCloseKey(aspectKey); 269 269 } 270 270 … … 280 280 // ---------------------------------------------------------------------- 281 281 HRESULT WIN32API OleSetContainedObject 282 (LPUNKNOWN pUnknown,283 BOOL 284 { 285 IRunnableObject * 286 HRESULT 282 (LPUNKNOWN pUnknown, 283 BOOL fContained) 284 { 285 IRunnableObject * runnable = NULL; 286 HRESULT hres; 287 287 288 288 dprintf(("OLE32: OleSetContainedObject")); … … 292 292 if (SUCCEEDED(hres)) 293 293 { 294 295 296 297 298 294 hres = IRunnableObject_SetContainedObject(runnable, fContained); 295 296 IRunnableObject_Release(runnable); 297 298 return hres; 299 299 } 300 300 … … 306 306 // ---------------------------------------------------------------------- 307 307 HRESULT WIN32API OleLoad 308 (LPSTORAGE pStg,309 REFIID riid,310 LPOLECLIENTSITE pClientSite,311 LPVOID * 312 { 313 IPersistStorage * 314 IOleObject * 315 STATSTG 316 HRESULT 308 (LPSTORAGE pStg, 309 REFIID riid, 310 LPOLECLIENTSITE pClientSite, 311 LPVOID * ppvObj) 312 { 313 IPersistStorage * persistStorage = NULL; 314 IOleObject * oleObject = NULL; 315 STATSTG storageInfo; 316 HRESULT hres; 317 317 318 318 dprintf(("OLE32: OleLoad")); … … 325 325 // Now, try and create the handler for the object 326 326 hres = CoCreateInstance(&storageInfo.clsid, 327 328 329 330 327 NULL, 328 CLSCTX_INPROC_HANDLER, 329 &IID_IOleObject, 330 (void**)&oleObject); 331 331 332 332 // If that fails, as it will most times, load the default OLE handler. 333 333 if (FAILED(hres)) 334 334 { 335 336 337 338 335 hres = OleCreateDefaultHandler(&storageInfo.clsid, 336 NULL, 337 &IID_IOleObject, 338 (void**)&oleObject); 339 339 } 340 340 341 341 // If we couldn't find a handler... this is bad. Abort the whole thing. 342 342 if (FAILED(hres)) 343 343 return hres; 344 344 345 345 // Inform the new object of it's client site. … … 349 349 hres = IOleObject_QueryInterface(oleObject, &IID_IPersistStorage, (void**)&persistStorage); 350 350 351 if (SUCCEEDED(hres)) 352 { 353 354 355 356 351 if (SUCCEEDED(hres)) 352 { 353 IPersistStorage_Load(persistStorage, pStg); 354 355 IPersistStorage_Release(persistStorage); 356 persistStorage = NULL; 357 357 } 358 358 … … 370 370 // ---------------------------------------------------------------------- 371 371 HRESULT WIN32API OleSave 372 (LPPERSISTSTORAGE 373 LPSTORAGE 374 BOOL 375 { 376 HRESULT 377 CLSID 372 (LPPERSISTSTORAGE pPS, 373 LPSTORAGE pStg, 374 BOOL fSameAsLoad) 375 { 376 HRESULT hres; 377 CLSID objectClass; 378 378 379 379 dprintf(("OLE32: OleSave")); … … 383 383 384 384 if (SUCCEEDED(hres)) 385 385 WriteClassStg(pStg, &objectClass); 386 386 387 387 // Then, we ask the object to save itself to the … … 390 390 391 391 if (SUCCEEDED(hres)) 392 392 IStorage_Commit(pStg, STGC_DEFAULT); 393 393 394 394 return hres; … … 402 402 switch (pmedium->tymed) 403 403 { 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 404 case TYMED_HGLOBAL: 405 { 406 if ( (pmedium->pUnkForRelease == 0) && (pmedium->u.hGlobal != 0) ) 407 GlobalFree(pmedium->u.hGlobal); 408 409 pmedium->u.hGlobal = 0; 410 break; 411 } 412 case TYMED_FILE: 413 { 414 if (pmedium->u.lpszFileName != 0) 415 { 416 if (pmedium->pUnkForRelease == 0) 417 DeleteFileW(pmedium->u.lpszFileName); 418 419 CoTaskMemFree(pmedium->u.lpszFileName); 420 } 421 422 pmedium->u.lpszFileName = 0; 423 break; 424 } 425 case TYMED_ISTREAM: 426 { 427 if (pmedium->u.pstm != 0) 428 IStream_Release(pmedium->u.pstm); 429 430 pmedium->u.pstm = 0; 431 break; 432 } 433 case TYMED_ISTORAGE: 434 { 435 if (pmedium->u.pstg != 0) 436 IStorage_Release(pmedium->u.pstg); 437 438 pmedium->u.pstg = 0; 439 break; 440 } 441 case TYMED_GDI: 442 { 443 if ( (pmedium->pUnkForRelease == 0) && (pmedium->u.hGlobal != 0) ) 444 DeleteObject(pmedium->u.hGlobal); 445 446 pmedium->u.hGlobal = 0; 447 break; 448 } 449 case TYMED_MFPICT: 450 { 451 if ( (pmedium->pUnkForRelease == 0) && (pmedium->u.hMetaFilePict != 0) ) 452 { 453 DeleteMetaFile(pmedium->u.hMetaFilePict); 454 GlobalFree(pmedium->u.hMetaFilePict); 455 } 456 457 pmedium->u.hMetaFilePict = 0; 458 break; 459 } 460 case TYMED_ENHMF: 461 { 462 if ( (pmedium->pUnkForRelease == 0) && (pmedium->u.hEnhMetaFile != 0) ) 463 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile); 464 465 pmedium->u.hEnhMetaFile = 0; 466 break; 467 } 468 case TYMED_NULL: 469 // Do nothing 470 break; 471 472 default: 473 break; 474 474 } 475 475 … … 477 477 if (pmedium->pUnkForRelease != 0) 478 478 { 479 480 481 } 482 } 483 484 // ====================================================================== 479 IUnknown_Release(pmedium->pUnkForRelease); 480 pmedium->pUnkForRelease = 0; 481 } 482 } 483 484 // ====================================================================== 485 485 // Private functions. 486 // ====================================================================== 486 // ====================================================================== 487 487 488 488 /*** … … 495 495 * params: 496 496 * regKey - Key to read the default value from 497 * pdwValue - Pointer to the location where the DWORD 497 * pdwValue - Pointer to the location where the DWORD 498 498 * value is returned. This value is not modified 499 499 * if the value is not found. … … 501 501 502 502 static void OLEUTL_ReadRegistryDWORDValue( 503 HKEY regKey, 503 HKEY regKey, 504 504 DWORD* pdwValue) 505 505 { … … 510 510 511 511 lres = RegQueryValueExA(regKey, 512 513 514 515 516 512 "", 513 NULL, 514 &dwKeyType, 515 (LPBYTE)buffer, 516 &cbData); 517 517 518 518 if (lres == ERROR_SUCCESS) … … 521 521 { 522 522 case REG_DWORD: 523 524 523 *pdwValue = *(DWORD*)buffer; 524 break; 525 525 case REG_EXPAND_SZ: 526 526 case REG_MULTI_SZ: 527 527 case REG_SZ: 528 529 528 *pdwValue = (DWORD)strtoul(buffer, NULL, 10); 529 break; 530 530 } 531 531 }
Note:
See TracChangeset
for help on using the changeset viewer.