Ignore:
Timestamp:
Oct 22, 1999, 2:18:46 PM (26 years ago)
Author:
phaller
Message:

Fix: debug info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/memorystream.cpp

    r1215 r1398  
    1 /* $Id: memorystream.cpp,v 1.2 1999-10-09 11:17:00 sandervl Exp $ */
     1/* $Id: memorystream.cpp,v 1.3 1999-10-22 12:18:46 phaller Exp $ */
     2
    23/*
    3  *      this class implements a pure IStream object
    4  *      and can be used for many purposes
     4 * Win32 SHELL32 for OS/2
    55 *
    6  *      the main reason for implementing this was
    7  *      a cleaner implementation of IShellLink which
    8  *      needs to be able to load lnk's from a IStream
    9  *      interface so it was obvious to capsule the file
    10  *      access in a IStream to.
     6 * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
     7 * Project Odin Software License can be found in LICENSE.TXT
     8 *
     9 * this class implements a pure IStream object
     10 * and can be used for many purposes
     11 *
     12 * the main reason for implementing this was
     13 * a cleaner implementation of IShellLink which
     14 * needs to be able to load lnk's from a IStream
     15 * interface so it was obvious to capsule the file
     16 * access in a IStream to.
    1117 */
    1218
     19
     20/*****************************************************************************
     21 * Includes                                                                  *
     22 *****************************************************************************/
     23
     24#include <odin.h>
     25#include <odinwrap.h>
     26#include <os2sel.h>
     27
    1328#include <string.h>
    14 #include <odin.h>
    1529
    1630#define ICOM_CINTERFACE 1
     
    2539#include <misc.h>
    2640
    27 DEFAULT_DEBUG_CHANNEL(shell)
     41
     42ODINDEBUGCHANNEL(SHELL32-MEMORYSTREAM)
     43
     44
     45/*****************************************************************************
     46 * Local Prototypes                                                          *
     47 *****************************************************************************/
    2848
    2949static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj);
     
    4363
    4464static ICOM_VTABLE(IStream) stvt =
    45 {       
    46         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    47         IStream_fnQueryInterface,
    48         IStream_fnAddRef,
    49         IStream_fnRelease,
    50         IStream_fnRead,
    51         IStream_fnWrite,
    52         IStream_fnSeek,
    53         IStream_fnSetSize,
    54         IStream_fnCopyTo,
    55         IStream_fnCommit,
    56         IStream_fnRevert,
    57         IStream_fnLockRegion,
    58         IStream_fnUnlockRegion,
    59         IStream_fnStat,
    60         IStream_fnClone
    61        
     65{
     66   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
     67   IStream_fnQueryInterface,
     68   IStream_fnAddRef,
     69   IStream_fnRelease,
     70   IStream_fnRead,
     71   IStream_fnWrite,
     72   IStream_fnSeek,
     73   IStream_fnSetSize,
     74   IStream_fnCopyTo,
     75   IStream_fnCommit,
     76   IStream_fnRevert,
     77   IStream_fnLockRegion,
     78   IStream_fnUnlockRegion,
     79   IStream_fnStat,
     80   IStream_fnClone
     81
    6282};
    6383
    6484typedef struct
    65 {       ICOM_VTABLE(IStream)    *lpvtst;
    66         DWORD           ref;
    67         LPBYTE          pImage;
    68         HANDLE          hMapping;
    69         DWORD           dwLength;
    70         DWORD           dwPos;
     85{  ICOM_VTABLE(IStream)                  *lpvtst;
     86   DWORD    ref;
     87   LPBYTE      pImage;
     88   HANDLE      hMapping;
     89   DWORD    dwLength;
     90   DWORD    dwPos;
    7191} ISHFileStream;
    7292
     
    7898HRESULT CreateStreamOnFile (LPCSTR pszFilename, IStream ** ppstm)
    7999{
    80         ISHFileStream*  fstr;
    81         OFSTRUCT        ofs;
    82         HFILE           hFile = OpenFile( pszFilename, &ofs, OF_READ );
    83         HRESULT         ret = E_FAIL;
    84        
    85         fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHFileStream));
    86         fstr->lpvtst=&stvt;
    87         fstr->ref = 1;
    88         fstr->dwLength = GetFileSize (hFile, NULL);
    89 
    90         shell32_ObjCount++;
    91 
    92         if (!(fstr->hMapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
    93         {
    94           WARN("failed to create filemap.\n");
    95           goto end_2;
    96         }
    97 
    98         if (!(fstr->pImage = (BYTE*)MapViewOfFile(fstr->hMapping,FILE_MAP_READ,0,0,0)))
    99         {
    100           WARN("failed to mmap filemap.\n");
    101           goto end_3;
    102         }
    103 
    104         ret = S_OK;
    105         goto end_1;
    106        
    107 end_3:  CloseHandle(fstr->hMapping);
    108 end_2:  HeapFree(GetProcessHeap(), 0, fstr);
    109         fstr = NULL;
    110 
    111 end_1:  _lclose(hFile);
    112         (*ppstm) = (IStream*)fstr;
    113         return ret;
     100   ISHFileStream* fstr;
     101   OFSTRUCT ofs;
     102   HFILE    hFile = OpenFile( pszFilename, &ofs, OF_READ );
     103   HRESULT     ret = E_FAIL;
     104
     105   dprintf(("SHELL32:MemoryStream CreateStreamOnFile(%s,%08xh)\n",
     106            pszFilename,
     107            ppstm));
     108
     109   fstr = (ISHFileStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHFileStream));
     110   fstr->lpvtst=&stvt;
     111   fstr->ref = 1;
     112   fstr->dwLength = GetFileSize (hFile, NULL);
     113
     114   shell32_ObjCount++;
     115
     116   if (!(fstr->hMapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL)))
     117   {
     118     dprintf(("failed to create filemap.\n"));
     119     goto end_2;
     120   }
     121
     122   if (!(fstr->pImage = (BYTE*)MapViewOfFile(fstr->hMapping,FILE_MAP_READ,0,0,0)))
     123   {
     124     dprintf(("failed to mmap filemap.\n"));
     125     goto end_3;
     126   }
     127
     128   ret = S_OK;
     129   goto end_1;
     130
     131end_3:   CloseHandle(fstr->hMapping);
     132end_2:   HeapFree(GetProcessHeap(), 0, fstr);
     133   fstr = NULL;
     134
     135end_1:   _lclose(hFile);
     136   (*ppstm) = (IStream*)fstr;
     137   return ret;
    114138}
    115139
     
    119143static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
    120144{
    121         ICOM_THIS(ISHFileStream, iface);
    122 
    123         char    xriid[50];
    124         WINE_StringFromCLSID((LPCLSID)riid,xriid);
    125 
    126         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
    127 
    128         *ppvObj = NULL;
    129 
    130         if(IsEqualIID(riid, &IID_IUnknown) ||
    131            IsEqualIID(riid, &IID_IStream))
    132         {
    133           *ppvObj = This;
    134         }
    135 
    136         if(*ppvObj)
    137         {
    138           IStream_AddRef((IStream*)*ppvObj);
    139           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
    140           return S_OK;
    141         }
    142         TRACE("-- Interface: E_NOINTERFACE\n");
    143         return E_NOINTERFACE;
     145   ICOM_THIS(ISHFileStream, iface);
     146
     147   char    xriid[50];
     148   WINE_StringFromCLSID((LPCLSID)riid,xriid);
     149
     150   dprintf(("SHELL32:MemoryStream IStream_fnQueryInterface(%p)->(\n\tIID:\t%s,%p)\n",
     151            This,xriid,ppvObj));
     152
     153   *ppvObj = NULL;
     154
     155   if(IsEqualIID(riid, &IID_IUnknown) ||
     156      IsEqualIID(riid, &IID_IStream))
     157   {
     158     *ppvObj = This;
     159   }
     160
     161   if(*ppvObj)
     162   {
     163     IStream_AddRef((IStream*)*ppvObj);
     164     dprintf(("Interface: (%p)->(%p)\n",ppvObj,*ppvObj));
     165     return S_OK;
     166   }
     167   dprintf(("-- Interface: E_NOINTERFACE\n"));
     168   return E_NOINTERFACE;
    144169}
    145170
     
    149174static ULONG WINAPI IStream_fnAddRef(IStream *iface)
    150175{
    151         ICOM_THIS(ISHFileStream, iface);
    152 
    153         TRACE("(%p)->(count=%lu)\n",This, This->ref);
    154 
    155         shell32_ObjCount++;
    156         return ++(This->ref);
     176   ICOM_THIS(ISHFileStream, iface);
     177
     178   dprintf(("SHELL32:MemoryStream IStream_fnAddRef (%p)->(count=%lu)\n",
     179            This, This->ref));
     180
     181   shell32_ObjCount++;
     182   return ++(This->ref);
    157183}
    158184
     
    162188static ULONG WINAPI IStream_fnRelease(IStream *iface)
    163189{
    164         ICOM_THIS(ISHFileStream, iface);
    165 
    166         TRACE("(%p)->()\n",This);
    167 
    168         shell32_ObjCount--;
    169 
    170         if (!--(This->ref))
    171         { TRACE(" destroying SHFileStream (%p)\n",This);
    172 
    173           UnmapViewOfFile(This->pImage);
    174           CloseHandle(This->hMapping);
    175 
    176           HeapFree(GetProcessHeap(),0,This);
    177           return 0;
    178         }
    179         return This->ref;
     190   ICOM_THIS(ISHFileStream, iface);
     191
     192   dprintf(("SHELL32:MemoryStream IStream_fnRelease(%p)->()\n",
     193            This));
     194
     195   shell32_ObjCount--;
     196
     197   if (!--(This->ref))
     198   { dprintf((" destroying SHFileStream (%p)\n",This));
     199
     200     UnmapViewOfFile(This->pImage);
     201     CloseHandle(This->hMapping);
     202
     203     HeapFree(GetProcessHeap(),0,This);
     204     return 0;
     205   }
     206   return This->ref;
    180207}
    181208
    182209static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
    183210{
    184         ICOM_THIS(ISHFileStream, iface);
    185 
    186         DWORD dwBytesToRead, dwBytesLeft;
    187        
    188         TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
    189        
    190         if ( !pv )
    191           return STG_E_INVALIDPOINTER;
    192 
    193         dwBytesLeft = This->dwLength - This->dwPos;
    194 
    195         if ( 0 >= dwBytesLeft )                                         /* end of buffer */
    196           return S_FALSE;
    197        
    198         dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
    199 
    200         memmove ( pv, (This->pImage) + (This->dwPos), dwBytesToRead);
    201        
    202         This->dwPos += dwBytesToRead;                                   /* adjust pointer */
    203 
    204         if (pcbRead)
    205           *pcbRead = dwBytesToRead;
    206 
    207         return S_OK;
     211   DWORD dwBytesToRead, dwBytesLeft;
     212
     213   ICOM_THIS(ISHFileStream, iface);
     214
     215   dprintf(("SHELL32:MemoryStream IStream_fnRead(%p)->(%p,%p,%p)\n",
     216            This, pv, cb, pcbRead));
     217
     218   if ( !pv )
     219     return STG_E_INVALIDPOINTER;
     220
     221   dwBytesLeft = This->dwLength - This->dwPos;
     222
     223   if ( 0 >= dwBytesLeft )                              /* end of buffer */
     224     return S_FALSE;
     225
     226   dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
     227
     228   memmove ( pv, (This->pImage) + (This->dwPos), dwBytesToRead);
     229
     230   This->dwPos += dwBytesToRead;                     /* adjust pointer */
     231
     232   if (pcbRead)
     233     *pcbRead = dwBytesToRead;
     234
     235   return S_OK;
    208236}
    209237static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
    210238{
    211         ICOM_THIS(ISHFileStream, iface);
    212 
    213         TRACE("(%p)\n",This);
    214 
    215         return E_NOTIMPL;
     239   ICOM_THIS(ISHFileStream, iface);
     240
     241   dprintf(("SHELL32:MemoryStream IStream_fnWrite (%p) not implemented\n",This));
     242
     243   return E_NOTIMPL;
    216244}
    217245static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
    218246{
    219         ICOM_THIS(ISHFileStream, iface);
    220 
    221         TRACE("(%p)\n",This);
    222 
    223         return E_NOTIMPL;
     247   ICOM_THIS(ISHFileStream, iface);
     248
     249   dprintf(("SHELL32:MemoryStream IStream_fnSeek (%p) not implemented\n",This));
     250
     251   return E_NOTIMPL;
    224252}
    225253static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
    226254{
    227         ICOM_THIS(ISHFileStream, iface);
    228 
    229         TRACE("(%p)\n",This);
    230 
    231         return E_NOTIMPL;
     255   ICOM_THIS(ISHFileStream, iface);
     256
     257   dprintf(("SHELL32:MemoryStream IStream_fnSetSize (%p) not implemented\n",This));
     258
     259   return E_NOTIMPL;
    232260}
    233261static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
    234262{
    235         ICOM_THIS(ISHFileStream, iface);
    236 
    237         TRACE("(%p)\n",This);
    238 
    239         return E_NOTIMPL;
     263   ICOM_THIS(ISHFileStream, iface);
     264
     265   dprintf(("SHELL32:MemoryStream IStream_fnCopyTo (%p) not implemented\n",This));
     266
     267   return E_NOTIMPL;
    240268}
    241269static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
    242270{
    243         ICOM_THIS(ISHFileStream, iface);
    244 
    245         TRACE("(%p)\n",This);
    246 
    247         return E_NOTIMPL;
     271   ICOM_THIS(ISHFileStream, iface);
     272
     273   dprintf(("SHELL32:MemoryStream IStream_fnCommit (%p) not implemented\n",This));
     274
     275   return E_NOTIMPL;
    248276}
    249277static HRESULT WINAPI IStream_fnRevert (IStream * iface)
    250278{
    251         ICOM_THIS(ISHFileStream, iface);
    252 
    253         TRACE("(%p)\n",This);
    254 
    255         return E_NOTIMPL;
     279   ICOM_THIS(ISHFileStream, iface);
     280
     281   dprintf(("SHELL32:MemoryStream IStream_fnRevert (%p) not implemented\n",This));
     282
     283   return E_NOTIMPL;
    256284}
    257285static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
    258286{
    259         ICOM_THIS(ISHFileStream, iface);
    260 
    261         TRACE("(%p)\n",This);
    262 
    263         return E_NOTIMPL;
     287   ICOM_THIS(ISHFileStream, iface);
     288
     289   dprintf(("SHELL32:MemoryStream IStream_fnLockRegion (%p) not implemented\n",This));
     290
     291   return E_NOTIMPL;
    264292}
    265293static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
    266294{
    267         ICOM_THIS(ISHFileStream, iface);
    268 
    269         TRACE("(%p)\n",This);
    270 
    271         return E_NOTIMPL;
     295   ICOM_THIS(ISHFileStream, iface);
     296
     297   dprintf(("SHELL32:MemoryStream IStream_fnUnlockRegoin (%p) not implemented.\n",This));
     298
     299   return E_NOTIMPL;
    272300}
    273301static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG*   pstatstg, DWORD grfStatFlag)
    274302{
    275         ICOM_THIS(ISHFileStream, iface);
    276 
    277         TRACE("(%p)\n",This);
    278 
    279         return E_NOTIMPL;
     303   ICOM_THIS(ISHFileStream, iface);
     304
     305   dprintf(("SHELL32:MemoryStream IStream_fnStat (%p) not implemented.\n",This));
     306
     307   return E_NOTIMPL;
    280308}
    281309static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
    282310{
    283         ICOM_THIS(ISHFileStream, iface);
    284 
    285         TRACE("(%p)\n",This);
    286 
    287         return E_NOTIMPL;
    288 }
     311   ICOM_THIS(ISHFileStream, iface);
     312
     313   dprintf(("SHELL32:MemoryStream IStream_fnClone (%p) not implemented.\n",This));
     314
     315   return E_NOTIMPL;
     316}
Note: See TracChangeset for help on using the changeset viewer.