Ignore:
Timestamp:
Sep 5, 2001, 3:54:53 PM (24 years ago)
Author:
bird
Message:

Added $Id:$ keyword.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shlwapi/regstream.c

    r6375 r6650  
     1/* $Id: regstream.c,v 1.3 2001-09-05 13:48:38 bird Exp $ */
    12/*
    2  *      SHRegOpenStream
     3 *  SHRegOpenStream
    34 */
    45#ifdef __WIN32OS2__
     
    2829DEFAULT_DEBUG_CHANNEL(shell);
    2930
    30 typedef struct 
    31 {       ICOM_VFIELD(IStream);
    32         DWORD           ref;
    33         HKEY            hKey;
    34         LPBYTE          pbBuffer;
    35         DWORD           dwLength;
    36         DWORD           dwPos;
     31typedef struct
     32{   ICOM_VFIELD(IStream);
     33    DWORD       ref;
     34    HKEY        hKey;
     35    LPBYTE      pbBuffer;
     36    DWORD       dwLength;
     37    DWORD       dwPos;
    3738} ISHRegStream;
    3839
     
    4041
    4142/**************************************************************************
    42 *   IStream_ConstructorA        [internal]
     43*   IStream_ConstructorA    [internal]
    4344*/
    4445static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
    4546{
    46         ISHRegStream*   rstr;
    47         DWORD           dwType;
    48        
    49         rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
    50 
    51         ICOM_VTBL(rstr)=&rstvt;
    52         rstr->ref = 1;
    53 
    54         if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
    55         {
    56           if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
    57           {
    58             /* read the binary data into the buffer */
    59             if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
    60             {
    61               if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
    62               {
    63                 if (dwType == REG_BINARY )
    64                 {
    65                   TRACE ("%p\n", rstr);
    66                   return (IStream*)rstr;
    67                 }
    68               }
    69               HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
    70             }
    71           }
    72           RegCloseKey(rstr->hKey);
    73         }
    74         HeapFree (GetProcessHeap(),0,rstr);
    75         return NULL;
    76 }
    77 
    78 /**************************************************************************
    79 *   IStream_ConstructorW        [internal]
     47    ISHRegStream*   rstr;
     48    DWORD       dwType;
     49
     50    rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
     51
     52    ICOM_VTBL(rstr)=&rstvt;
     53    rstr->ref = 1;
     54
     55    if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
     56    {
     57      if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
     58      {
     59        /* read the binary data into the buffer */
     60        if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
     61        {
     62          if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
     63          {
     64            if (dwType == REG_BINARY )
     65            {
     66              TRACE ("%p\n", rstr);
     67              return (IStream*)rstr;
     68            }
     69          }
     70          HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
     71        }
     72      }
     73      RegCloseKey(rstr->hKey);
     74    }
     75    HeapFree (GetProcessHeap(),0,rstr);
     76    return NULL;
     77}
     78
     79/**************************************************************************
     80*   IStream_ConstructorW    [internal]
    8081*/
    8182static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
    8283{
    83         ISHRegStream*   rstr;
    84         DWORD           dwType;
    85        
    86         rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
    87 
    88         ICOM_VTBL(rstr)=&rstvt;
    89         rstr->ref = 1;
    90 
    91         if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
    92         {
    93           if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
    94           {
    95             /* read the binary data into the buffer */
    96             if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
    97             {
    98               if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
    99               {
    100                 if (dwType == REG_BINARY )
    101                 {
    102                   TRACE ("%p\n", rstr);
    103                   return (IStream*)rstr;
    104                 }
    105               }
    106               HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
    107             }
    108           }
    109           RegCloseKey(rstr->hKey);
    110         }
    111         HeapFree (GetProcessHeap(),0,rstr);
    112         return NULL;
     84    ISHRegStream*   rstr;
     85    DWORD       dwType;
     86
     87    rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
     88
     89    ICOM_VTBL(rstr)=&rstvt;
     90    rstr->ref = 1;
     91
     92    if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
     93    {
     94      if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
     95      {
     96        /* read the binary data into the buffer */
     97        if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
     98        {
     99          if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
     100          {
     101            if (dwType == REG_BINARY )
     102            {
     103              TRACE ("%p\n", rstr);
     104              return (IStream*)rstr;
     105            }
     106          }
     107          HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
     108        }
     109      }
     110      RegCloseKey(rstr->hKey);
     111    }
     112    HeapFree (GetProcessHeap(),0,rstr);
     113    return NULL;
    113114}
    114115
     
    118119static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
    119120{
    120         ICOM_THIS(ISHRegStream, iface);
    121 
    122 ////    TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
    123 
    124         *ppvObj = NULL;
    125 
    126         if(IsEqualIID(riid, &IID_IUnknown))     /*IUnknown*/
    127         { *ppvObj = This;
    128         }
    129         else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
    130         { *ppvObj = This;
    131         }   
    132 
    133         if(*ppvObj)
    134         {
    135           IStream_AddRef((IStream*)*ppvObj);     
    136           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
    137           return S_OK;
    138         }
    139         TRACE("-- Interface: E_NOINTERFACE\n");
    140         return E_NOINTERFACE;
     121    ICOM_THIS(ISHRegStream, iface);
     122
     123////    TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
     124
     125    *ppvObj = NULL;
     126
     127    if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
     128    { *ppvObj = This;
     129    }
     130    else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
     131    { *ppvObj = This;
     132    }
     133
     134    if(*ppvObj)
     135    {
     136      IStream_AddRef((IStream*)*ppvObj);
     137      TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
     138      return S_OK;
     139    }
     140    TRACE("-- Interface: E_NOINTERFACE\n");
     141    return E_NOINTERFACE;
    141142}
    142143
     
    146147static ULONG WINAPI IStream_fnAddRef(IStream *iface)
    147148{
    148         ICOM_THIS(ISHRegStream, iface);
    149 
    150         TRACE("(%p)->(count=%lu)\n",This, This->ref);
    151 
    152         return ++(This->ref);
     149    ICOM_THIS(ISHRegStream, iface);
     150
     151    TRACE("(%p)->(count=%lu)\n",This, This->ref);
     152
     153    return ++(This->ref);
    153154}
    154155
     
    158159static ULONG WINAPI IStream_fnRelease(IStream *iface)
    159160{
    160         ICOM_THIS(ISHRegStream, iface);
    161 
    162         TRACE("(%p)->()\n",This);
    163 
    164         if (!--(This->ref))
    165         { TRACE(" destroying SHReg IStream (%p)\n",This);
    166 
    167           if (This->pbBuffer)
    168             HeapFree(GetProcessHeap(),0,This->pbBuffer);
    169 
    170           if (This->hKey)
    171             RegCloseKey(This->hKey);
    172 
    173           HeapFree(GetProcessHeap(),0,This);
    174           return 0;
    175         }
    176         return This->ref;
     161    ICOM_THIS(ISHRegStream, iface);
     162
     163    TRACE("(%p)->()\n",This);
     164
     165    if (!--(This->ref))
     166    { TRACE(" destroying SHReg IStream (%p)\n",This);
     167
     168      if (This->pbBuffer)
     169        HeapFree(GetProcessHeap(),0,This->pbBuffer);
     170
     171      if (This->hKey)
     172        RegCloseKey(This->hKey);
     173
     174      HeapFree(GetProcessHeap(),0,This);
     175      return 0;
     176    }
     177    return This->ref;
    177178}
    178179
    179180static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
    180181{
    181         ICOM_THIS(ISHRegStream, iface);
    182 
    183         DWORD dwBytesToRead, dwBytesLeft;
    184        
    185         TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
    186        
    187         if ( !pv )
    188           return STG_E_INVALIDPOINTER;
    189          
    190         dwBytesLeft = This->dwLength - This->dwPos;
    191 
    192         if ( 0 >= dwBytesLeft )                                         /* end of buffer */
    193           return S_FALSE;
    194        
    195         dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
    196 
    197         memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
    198        
    199         This->dwPos += dwBytesToRead;                                   /* adjust pointer */
    200 
    201         if (pcbRead)
    202           *pcbRead = dwBytesToRead;
    203 
    204         return S_OK;
     182    ICOM_THIS(ISHRegStream, iface);
     183
     184    DWORD dwBytesToRead, dwBytesLeft;
     185
     186    TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
     187
     188    if ( !pv )
     189      return STG_E_INVALIDPOINTER;
     190
     191    dwBytesLeft = This->dwLength - This->dwPos;
     192
     193    if ( 0 >= dwBytesLeft )                     /* end of buffer */
     194      return S_FALSE;
     195
     196    dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
     197
     198    memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
     199
     200    This->dwPos += dwBytesToRead;                   /* adjust pointer */
     201
     202    if (pcbRead)
     203      *pcbRead = dwBytesToRead;
     204
     205    return S_OK;
    205206}
    206207static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
    207208{
    208         ICOM_THIS(ISHRegStream, iface);
    209 
    210         TRACE("(%p)\n",This);
    211 
    212         return E_NOTIMPL;
     209    ICOM_THIS(ISHRegStream, iface);
     210
     211    TRACE("(%p)\n",This);
     212
     213    return E_NOTIMPL;
    213214}
    214215static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
    215216{
    216         ICOM_THIS(ISHRegStream, iface);
    217 
    218         TRACE("(%p)\n",This);
    219 
    220         return E_NOTIMPL;
     217    ICOM_THIS(ISHRegStream, iface);
     218
     219    TRACE("(%p)\n",This);
     220
     221    return E_NOTIMPL;
    221222}
    222223static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
    223224{
    224         ICOM_THIS(ISHRegStream, iface);
    225 
    226         TRACE("(%p)\n",This);
    227 
    228         return E_NOTIMPL;
     225    ICOM_THIS(ISHRegStream, iface);
     226
     227    TRACE("(%p)\n",This);
     228
     229    return E_NOTIMPL;
    229230}
    230231static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
    231232{
    232         ICOM_THIS(ISHRegStream, iface);
    233 
    234         TRACE("(%p)\n",This);
    235 
    236         return E_NOTIMPL;
     233    ICOM_THIS(ISHRegStream, iface);
     234
     235    TRACE("(%p)\n",This);
     236
     237    return E_NOTIMPL;
    237238}
    238239static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
    239240{
    240         ICOM_THIS(ISHRegStream, iface);
    241 
    242         TRACE("(%p)\n",This);
    243 
    244         return E_NOTIMPL;
     241    ICOM_THIS(ISHRegStream, iface);
     242
     243    TRACE("(%p)\n",This);
     244
     245    return E_NOTIMPL;
    245246}
    246247static HRESULT WINAPI IStream_fnRevert (IStream * iface)
    247248{
    248         ICOM_THIS(ISHRegStream, iface);
    249 
    250         TRACE("(%p)\n",This);
    251 
    252         return E_NOTIMPL;
     249    ICOM_THIS(ISHRegStream, iface);
     250
     251    TRACE("(%p)\n",This);
     252
     253    return E_NOTIMPL;
    253254}
    254255static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
    255256{
    256         ICOM_THIS(ISHRegStream, iface);
    257 
    258         TRACE("(%p)\n",This);
    259 
    260         return E_NOTIMPL;
     257    ICOM_THIS(ISHRegStream, iface);
     258
     259    TRACE("(%p)\n",This);
     260
     261    return E_NOTIMPL;
    261262}
    262263static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
    263264{
    264         ICOM_THIS(ISHRegStream, iface);
    265 
    266         TRACE("(%p)\n",This);
    267 
    268         return E_NOTIMPL;
     265    ICOM_THIS(ISHRegStream, iface);
     266
     267    TRACE("(%p)\n",This);
     268
     269    return E_NOTIMPL;
    269270}
    270271static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG*   pstatstg, DWORD grfStatFlag)
    271272{
    272         ICOM_THIS(ISHRegStream, iface);
    273 
    274         TRACE("(%p)\n",This);
    275 
    276         return E_NOTIMPL;
     273    ICOM_THIS(ISHRegStream, iface);
     274
     275    TRACE("(%p)\n",This);
     276
     277    return E_NOTIMPL;
    277278}
    278279static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
    279280{
    280         ICOM_THIS(ISHRegStream, iface);
    281 
    282         TRACE("(%p)\n",This);
    283 
    284         return E_NOTIMPL;
    285 }
    286 
    287 static struct ICOM_VTABLE(IStream) rstvt = 
    288 {       
    289         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    290         IStream_fnQueryInterface,
    291         IStream_fnAddRef,
    292         IStream_fnRelease,
    293         IStream_fnRead,
    294         IStream_fnWrite,
    295         IStream_fnSeek,
    296         IStream_fnSetSize,
    297         IStream_fnCopyTo,
    298         IStream_fnCommit,
    299         IStream_fnRevert,
    300         IStream_fnLockRegion,
    301         IStream_fnUnlockRegion,
    302         IStream_fnStat,
    303         IStream_fnClone
    304        
     281    ICOM_THIS(ISHRegStream, iface);
     282
     283    TRACE("(%p)\n",This);
     284
     285    return E_NOTIMPL;
     286}
     287
     288static struct ICOM_VTABLE(IStream) rstvt =
     289{
     290    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     291    IStream_fnQueryInterface,
     292    IStream_fnAddRef,
     293    IStream_fnRelease,
     294    IStream_fnRead,
     295    IStream_fnWrite,
     296    IStream_fnSeek,
     297    IStream_fnSetSize,
     298    IStream_fnCopyTo,
     299    IStream_fnCommit,
     300    IStream_fnRevert,
     301    IStream_fnLockRegion,
     302    IStream_fnUnlockRegion,
     303    IStream_fnStat,
     304    IStream_fnClone
     305
    305306};
    306307
    307308/*************************************************************************
    308  * SHOpenRegStreamA                             [SHLWAPI.@]
     309 * SHOpenRegStreamA             [SHLWAPI.@]
    309310 */
    310311IStream * WINAPI SHOpenRegStreamA(
    311         HKEY hkey,
    312         LPCSTR pszSubkey,
    313         LPCSTR pszValue,
    314         DWORD grfMode)
    315 {
    316         TRACE("(0x%08x,%s,%s,0x%08lx)\n",
    317         hkey, pszSubkey, pszValue, grfMode);
    318 
    319         return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
     312    HKEY hkey,
     313    LPCSTR pszSubkey,
     314    LPCSTR pszValue,
     315    DWORD grfMode)
     316{
     317    TRACE("(0x%08x,%s,%s,0x%08lx)\n",
     318    hkey, pszSubkey, pszValue, grfMode);
     319
     320    return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
    320321}
    321322
    322323/*************************************************************************
    323  * SHOpenRegStreamW                             [SHLWAPI.@]
     324 * SHOpenRegStreamW             [SHLWAPI.@]
    324325 */
    325326IStream * WINAPI SHOpenRegStreamW(
    326         HKEY hkey,
    327         LPCWSTR pszSubkey,
    328         LPCWSTR pszValue,
    329         DWORD grfMode)
    330 {
    331         TRACE("(0x%08x,%s,%s,0x%08lx)\n",
    332         hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
    333 
    334         return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);
    335 }
     327    HKEY hkey,
     328    LPCWSTR pszSubkey,
     329    LPCWSTR pszValue,
     330    DWORD grfMode)
     331{
     332    TRACE("(0x%08x,%s,%s,0x%08lx)\n",
     333    hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
     334
     335    return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);
     336}
Note: See TracChangeset for help on using the changeset viewer.