Changeset 5280


Ignore:
Timestamp:
Feb 28, 2001, 9:30:22 PM (24 years ago)
Author:
sandervl
Message:

put back old version

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 hugh Exp $ */
    2 /*
    3  *
     1/* $Id: ole2.cpp,v 1.5 2001-02-28 20:30:22 sandervl Exp $ */
     2/* 
     3 * 
    44 * Project Odin Software License can be found in LICENSE.TXT
    5  *
     5 * 
    66 */
    7 /*
     7/* 
    88 * OLE functions.
    9  *
     9 * 
    1010 * 2/9/99
    11  *
     11 * 
    1212 * Copyright 1999 David J. Raison
    1313 *
     
    1515 *   Copyright 1995  Martin von Loewis
    1616 *   Copyright 1999  Francis Beaudet
    17  *   Copyright 1999  Noel Borthwick
     17 *   Copyright 1999  Noel Borthwick 
    1818 */
    1919
     
    2424#include <assert.h>
    2525
    26 // ======================================================================
     26// ====================================================================== 
    2727// Local Data
    28 // ======================================================================
     28// ====================================================================== 
    2929
    3030/*
     
    3535
    3636
    37 // ======================================================================
     37// ====================================================================== 
    3838// Prototypes.
    39 // ======================================================================
     39// ====================================================================== 
    4040static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
    4141
    4242// These are the prototypes of the utility methods used to manage a shared menu
    43 extern  void  OLEMenu_Initialize();
    44 extern  void  OLEMenu_UnInitialize();
     43extern  void    OLEMenu_Initialize();
     44extern  void    OLEMenu_UnInitialize();
    4545
    4646// These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
    47 extern  void  OLEClipbrd_UnInitialize();
    48 extern  void  OLEClipbrd_Initialize();
     47extern  void    OLEClipbrd_UnInitialize();
     48extern  void    OLEClipbrd_Initialize();
    4949
    5050// These are the prototypes of the utility methods used for OLE Drag n Drop
    51 extern  void  OLEDD_Initialize();
    52 extern  void  OLEDD_UnInitialize();
    53 
    54 // ======================================================================
     51extern  void    OLEDD_Initialize();
     52extern  void    OLEDD_UnInitialize();
     53
     54// ====================================================================== 
    5555// Public API's
    56 // ======================================================================
     56// ====================================================================== 
    5757
    5858// ----------------------------------------------------------------------
     
    7777    hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    7878    if (FAILED(hr))
    79   return hr;
     79        return hr;   
    8080
    8181    // Then, it has to initialize the OLE specific modules.
     
    8787    if (++OLE_moduleLockCount == 1)
    8888    {
    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();
     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();
    9999    }
    100100
     
    121121    if (--OLE_moduleLockCount == 0)
    122122    {
    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();
     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();
    133133    }
    134134
     
    146146// ----------------------------------------------------------------------
    147147HRESULT WIN32API OleRegGetUserType
    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;
     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;
    159159
    160160    dprintf(("OLE32: OleRegGetUserType"));
     
    165165    tCLSID = "CLSID\\";
    166166    tCLSID += clsid;
    167     tCLSID += "}";
     167    tCLSID += "\\";
    168168
    169169    // Open the class id Key
    170170    hres = RegOpenKeyA(HKEY_CLASSES_ROOT, tCLSID, &clsidKey);
    171171    if (hres != ERROR_SUCCESS)
    172   return REGDB_E_CLASSNOTREG;
     172        return REGDB_E_CLASSNOTREG;
    173173
    174174    // Retrieve the size of the name string.
     
    177177    if (hres != ERROR_SUCCESS)
    178178    {
    179   RegCloseKey(clsidKey);
    180   return REGDB_E_READREGDB;
     179        RegCloseKey(clsidKey);
     180        return REGDB_E_READREGDB;
    181181    }
    182182
     
    186186    if (buffer == NULL)
    187187    {
    188   RegCloseKey(clsidKey);
    189   return E_OUTOFMEMORY;
     188        RegCloseKey(clsidKey);
     189        return E_OUTOFMEMORY;
    190190    }
    191191
     
    194194    if (hres != ERROR_SUCCESS)
    195195    {
    196   HeapFree(GetProcessHeap(), 0, buffer);
    197   return REGDB_E_READREGDB;
     196        HeapFree(GetProcessHeap(), 0, buffer);
     197        return REGDB_E_READREGDB;
    198198    }
    199199
     
    203203    if (*pszUserType == NULL)
    204204    {
    205   HeapFree(GetProcessHeap(), 0, buffer);
    206   return E_OUTOFMEMORY;
     205        HeapFree(GetProcessHeap(), 0, buffer);
     206        return E_OUTOFMEMORY;
    207207    }
    208208
     
    218218// ----------------------------------------------------------------------
    219219HRESULT WIN32API OleRegGetMiscStatus
    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;
     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;
    229229
    230230    dprintf(("OLE32: OleRegGetMiscStatus"));
     
    236236    tStr = "CLSID\\";
    237237    tStr += clsid;
    238     tStr += "}";
     238    tStr += "\\";
    239239    dprintf(("       Key   : %s", (char *)tStr));
    240240
     
    243243
    244244    if (result != ERROR_SUCCESS)
    245   return REGDB_E_CLASSNOTREG;
     245        return REGDB_E_CLASSNOTREG;
    246246
    247247    // Get the MiscStatus
     
    250250    if (result != ERROR_SUCCESS)
    251251    {
    252   RegCloseKey(clsidKey);
    253   return REGDB_E_READREGDB;
     252        RegCloseKey(clsidKey);
     253        return REGDB_E_READREGDB;
    254254    }
    255255
     
    258258
    259259    // Open the key specific to the requested aspect.
    260     oStringA    tKey(dwAspect);
     260    oStringA            tKey(dwAspect);
    261261    dprintf(("       Aspect: %s", (char *)tKey));
    262262
     
    265265    if (result == ERROR_SUCCESS)
    266266    {
    267   OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
    268   RegCloseKey(aspectKey);
     267        OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
     268        RegCloseKey(aspectKey);
    269269    }
    270270
     
    280280// ----------------------------------------------------------------------
    281281HRESULT WIN32API OleSetContainedObject
    282    (LPUNKNOWN   pUnknown,
    283     BOOL          fContained)
    284 {
    285     IRunnableObject * runnable = NULL;
    286     HRESULT           hres;
     282   (LPUNKNOWN           pUnknown,
     283    BOOL                fContained)
     284{
     285    IRunnableObject *   runnable = NULL;
     286    HRESULT             hres;
    287287
    288288    dprintf(("OLE32: OleSetContainedObject"));
     
    292292    if (SUCCEEDED(hres))
    293293    {
    294   hres = IRunnableObject_SetContainedObject(runnable, fContained);
    295 
    296   IRunnableObject_Release(runnable);
    297 
    298   return hres;
     294        hres = IRunnableObject_SetContainedObject(runnable, fContained);
     295
     296        IRunnableObject_Release(runnable);
     297
     298        return hres;
    299299    }
    300300
     
    306306// ----------------------------------------------------------------------
    307307HRESULT WIN32API OleLoad
    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;
     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;
    317317
    318318    dprintf(("OLE32: OleLoad"));
     
    325325    // Now, try and create the handler for the object
    326326    hres = CoCreateInstance(&storageInfo.clsid,
    327               NULL,
    328               CLSCTX_INPROC_HANDLER,
    329               &IID_IOleObject,
    330               (void**)&oleObject);
     327                            NULL,
     328                            CLSCTX_INPROC_HANDLER,
     329                            &IID_IOleObject,
     330                            (void**)&oleObject);
    331331
    332332    // If that fails, as it will most times, load the default OLE handler.
    333333    if (FAILED(hres))
    334334    {
    335   hres = OleCreateDefaultHandler(&storageInfo.clsid,
    336                NULL,
    337                &IID_IOleObject,
    338                (void**)&oleObject);
     335        hres = OleCreateDefaultHandler(&storageInfo.clsid,
     336                                       NULL,
     337                                       &IID_IOleObject,
     338                                       (void**)&oleObject);
    339339    }
    340340
    341341    // If we couldn't find a handler... this is bad. Abort the whole thing.
    342342    if (FAILED(hres))
    343   return hres;
     343        return hres;
    344344
    345345    // Inform the new object of it's client site.
     
    349349    hres = IOleObject_QueryInterface(oleObject, &IID_IPersistStorage, (void**)&persistStorage);
    350350
    351     if (SUCCEEDED(hres))
    352     {
    353   IPersistStorage_Load(persistStorage, pStg);
    354 
    355   IPersistStorage_Release(persistStorage);
    356   persistStorage = NULL;
     351    if (SUCCEEDED(hres)) 
     352    {
     353        IPersistStorage_Load(persistStorage, pStg);
     354
     355        IPersistStorage_Release(persistStorage);
     356        persistStorage = NULL;
    357357    }
    358358
     
    370370// ----------------------------------------------------------------------
    371371HRESULT WIN32API OleSave
    372    (LPPERSISTSTORAGE    pPS,
    373     LPSTORAGE           pStg,
    374     BOOL                fSameAsLoad)
    375 {
    376     HRESULT     hres;
    377     CLSID     objectClass;
     372   (LPPERSISTSTORAGE            pPS,
     373    LPSTORAGE                   pStg,
     374    BOOL                        fSameAsLoad)
     375{
     376    HRESULT                     hres;
     377    CLSID                       objectClass;
    378378
    379379    dprintf(("OLE32: OleSave"));
     
    383383
    384384    if (SUCCEEDED(hres))
    385   WriteClassStg(pStg, &objectClass);
     385        WriteClassStg(pStg, &objectClass);
    386386
    387387    // Then, we ask the object to save itself to the
     
    390390
    391391    if (SUCCEEDED(hres))
    392   IStorage_Commit(pStg, STGC_DEFAULT);
     392        IStorage_Commit(pStg, STGC_DEFAULT);
    393393
    394394    return hres;
     
    402402    switch (pmedium->tymed)
    403403    {
    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;
     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;
    474474    }
    475475
     
    477477    if (pmedium->pUnkForRelease != 0)
    478478    {
    479   IUnknown_Release(pmedium->pUnkForRelease);
    480   pmedium->pUnkForRelease = 0;
    481     }
    482 }
    483 
    484 // ======================================================================
     479        IUnknown_Release(pmedium->pUnkForRelease);
     480        pmedium->pUnkForRelease = 0;
     481    }
     482}
     483
     484// ====================================================================== 
    485485// Private functions.
    486 // ======================================================================
     486// ====================================================================== 
    487487
    488488/***
     
    495495 * params:
    496496 *     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 
    498498 *                value is returned. This value is not modified
    499499 *                if the value is not found.
     
    501501
    502502static void OLEUTL_ReadRegistryDWORDValue(
    503   HKEY   regKey,
     503  HKEY   regKey, 
    504504  DWORD* pdwValue)
    505505{
     
    510510
    511511  lres = RegQueryValueExA(regKey,
    512         "",
    513         NULL,
    514         &dwKeyType,
    515         (LPBYTE)buffer,
    516         &cbData);
     512                          "",
     513                          NULL,
     514                          &dwKeyType,
     515                          (LPBYTE)buffer,
     516                          &cbData);
    517517
    518518  if (lres == ERROR_SUCCESS)
     
    521521    {
    522522      case REG_DWORD:
    523   *pdwValue = *(DWORD*)buffer;
    524   break;
     523        *pdwValue = *(DWORD*)buffer;
     524        break;
    525525      case REG_EXPAND_SZ:
    526526      case REG_MULTI_SZ:
    527527      case REG_SZ:
    528   *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
    529   break;
     528        *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
     529        break;
    530530    }
    531531  }
Note: See TracChangeset for help on using the changeset viewer.