1999-03-27 17:15:22 +01:00
|
|
|
/*
|
|
|
|
* SHRegOpenStream
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "winerror.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "winbase.h"
|
1999-03-27 17:15:22 +01:00
|
|
|
#include "winreg.h"
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shlobj.h"
|
1999-03-27 17:15:22 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
#include "heap.h"
|
|
|
|
#include "debugtools.h"
|
1999-03-27 17:15:22 +01:00
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(shell);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1999-03-27 17:15:22 +01:00
|
|
|
typedef struct
|
1999-10-31 02:59:23 +01:00
|
|
|
{ ICOM_VFIELD(IStream);
|
1999-03-27 17:15:22 +01:00
|
|
|
DWORD ref;
|
|
|
|
HKEY hKey;
|
|
|
|
LPBYTE pbBuffer;
|
|
|
|
DWORD dwLength;
|
|
|
|
DWORD dwPos;
|
|
|
|
} ISHRegStream;
|
|
|
|
|
|
|
|
static struct ICOM_VTABLE(IStream) rstvt;
|
|
|
|
|
|
|
|
/**************************************************************************
|
2000-06-02 01:25:44 +02:00
|
|
|
* IStream_ConstructorA [internal]
|
1999-03-27 17:15:22 +01:00
|
|
|
*/
|
2000-07-26 19:51:32 +02:00
|
|
|
static IStream *IStream_ConstructorA(HKEY hKey, LPCSTR pszSubKey, LPCSTR pszValue, DWORD grfMode)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
ISHRegStream* rstr;
|
1999-03-27 17:15:22 +01:00
|
|
|
DWORD dwType;
|
|
|
|
|
|
|
|
rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
|
2000-06-02 01:25:44 +02:00
|
|
|
|
1999-10-31 02:59:23 +01:00
|
|
|
ICOM_VTBL(rstr)=&rstvt;
|
1999-03-27 17:15:22 +01:00
|
|
|
rstr->ref = 1;
|
|
|
|
|
2000-06-02 01:25:44 +02:00
|
|
|
if (!(RegOpenKeyExA (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
|
|
|
|
{
|
|
|
|
if (!(RegQueryValueExA(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
/* read the binary data into the buffer */
|
2000-06-02 01:25:44 +02:00
|
|
|
if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
|
|
|
|
{
|
|
|
|
if (!(RegQueryValueExA(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
|
|
|
|
{
|
|
|
|
if (dwType == REG_BINARY )
|
|
|
|
{
|
|
|
|
TRACE ("%p\n", rstr);
|
1999-03-27 17:15:22 +01:00
|
|
|
return (IStream*)rstr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(rstr->hKey);
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
HeapFree (GetProcessHeap(),0,rstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_ConstructorW [internal]
|
|
|
|
*/
|
2000-07-26 19:51:32 +02:00
|
|
|
static IStream *IStream_ConstructorW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD grfMode)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
ISHRegStream* rstr;
|
|
|
|
DWORD dwType;
|
|
|
|
|
|
|
|
rstr = (ISHRegStream*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ISHRegStream));
|
1999-03-27 17:15:22 +01:00
|
|
|
|
2000-06-02 01:25:44 +02:00
|
|
|
ICOM_VTBL(rstr)=&rstvt;
|
|
|
|
rstr->ref = 1;
|
|
|
|
|
|
|
|
if (!(RegOpenKeyExW (hKey, pszSubKey, 0, KEY_READ, &(rstr->hKey))))
|
|
|
|
{
|
|
|
|
if (!(RegQueryValueExW(rstr->hKey, pszValue,0,0,0,&(rstr->dwLength))))
|
|
|
|
{
|
|
|
|
/* read the binary data into the buffer */
|
|
|
|
if((rstr->pbBuffer = HeapAlloc(GetProcessHeap(),0,rstr->dwLength)))
|
|
|
|
{
|
|
|
|
if (!(RegQueryValueExW(rstr->hKey, pszValue,0,&dwType,rstr->pbBuffer,&(rstr->dwLength))))
|
|
|
|
{
|
|
|
|
if (dwType == REG_BINARY )
|
|
|
|
{
|
|
|
|
TRACE ("%p\n", rstr);
|
|
|
|
return (IStream*)rstr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree (GetProcessHeap(),0,rstr->pbBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(rstr->hKey);
|
1999-03-27 17:15:22 +01:00
|
|
|
}
|
|
|
|
HeapFree (GetProcessHeap(),0,rstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnQueryInterface
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
2000-01-18 06:09:49 +01:00
|
|
|
TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
|
|
|
|
{ *ppvObj = This;
|
|
|
|
}
|
|
|
|
else if(IsEqualIID(riid, &IID_IStream)) /*IStream*/
|
|
|
|
{ *ppvObj = This;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppvObj)
|
|
|
|
{
|
|
|
|
IStream_AddRef((IStream*)*ppvObj);
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
|
1999-03-27 17:15:22 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("-- Interface: E_NOINTERFACE\n");
|
1999-03-27 17:15:22 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnAddRef
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnAddRef(IStream *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)->(count=%lu)\n",This, This->ref);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return ++(This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IStream_fnRelease
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IStream_fnRelease(IStream *iface)
|
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)->()\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
if (!--(This->ref))
|
1999-06-12 17:45:58 +02:00
|
|
|
{ TRACE(" destroying SHReg IStream (%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
if (This->pbBuffer)
|
|
|
|
HeapFree(GetProcessHeap(),0,This->pbBuffer);
|
|
|
|
|
|
|
|
if (This->hKey)
|
|
|
|
RegCloseKey(This->hKey);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return This->ref;
|
|
|
|
}
|
|
|
|
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnRead (IStream * iface, void* pv, ULONG cb, ULONG* pcbRead)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
|
|
|
DWORD dwBytesToRead, dwBytesLeft;
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)->(%p,0x%08lx,%p)\n",This, pv, cb, pcbRead);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
if ( !pv )
|
|
|
|
return STG_E_INVALIDPOINTER;
|
|
|
|
|
|
|
|
dwBytesLeft = This->dwLength - This->dwPos;
|
|
|
|
|
|
|
|
if ( 0 >= dwBytesLeft ) /* end of buffer */
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
dwBytesToRead = ( cb > dwBytesLeft) ? dwBytesLeft : cb;
|
|
|
|
|
|
|
|
memmove ( pv, (This->pbBuffer) + (This->dwPos), dwBytesToRead);
|
|
|
|
|
|
|
|
This->dwPos += dwBytesToRead; /* adjust pointer */
|
|
|
|
|
|
|
|
if (pcbRead)
|
|
|
|
*pcbRead = dwBytesToRead;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnWrite (IStream * iface, const void* pv, ULONG cb, ULONG* pcbWritten)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnSeek (IStream * iface, LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnSetSize (IStream * iface, ULARGE_INTEGER libNewSize)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnCopyTo (IStream * iface, IStream* pstm, ULARGE_INTEGER cb, ULARGE_INTEGER* pcbRead, ULARGE_INTEGER* pcbWritten)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnCommit (IStream * iface, DWORD grfCommitFlags)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnRevert (IStream * iface)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnLockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnUnlockRegion (IStream * iface, ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnStat (IStream * iface, STATSTG* pstatstg, DWORD grfStatFlag)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
static HRESULT WINAPI IStream_fnClone (IStream * iface, IStream** ppstm)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
|
|
|
ICOM_THIS(ISHRegStream, iface);
|
|
|
|
|
1999-06-12 17:45:58 +02:00
|
|
|
TRACE("(%p)\n",This);
|
1999-03-27 17:15:22 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ICOM_VTABLE(IStream) rstvt =
|
|
|
|
{
|
1999-05-22 13:41:38 +02:00
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
1999-03-27 17:15:22 +01:00
|
|
|
IStream_fnQueryInterface,
|
|
|
|
IStream_fnAddRef,
|
|
|
|
IStream_fnRelease,
|
|
|
|
IStream_fnRead,
|
|
|
|
IStream_fnWrite,
|
|
|
|
IStream_fnSeek,
|
|
|
|
IStream_fnSetSize,
|
|
|
|
IStream_fnCopyTo,
|
|
|
|
IStream_fnCommit,
|
|
|
|
IStream_fnRevert,
|
|
|
|
IStream_fnLockRegion,
|
|
|
|
IStream_fnUnlockRegion,
|
|
|
|
IStream_fnStat,
|
|
|
|
IStream_fnClone
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************************************************************************
|
2000-07-26 19:51:32 +02:00
|
|
|
* SHOpenRegStreamA [SHLWAPI.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* SHOpenRegStream2A [SHLWAPI.@]
|
2000-06-02 01:25:44 +02:00
|
|
|
*/
|
|
|
|
IStream * WINAPI SHOpenRegStreamA(
|
|
|
|
HKEY hkey,
|
|
|
|
LPCSTR pszSubkey,
|
|
|
|
LPCSTR pszValue,
|
|
|
|
DWORD grfMode)
|
|
|
|
{
|
|
|
|
TRACE("(0x%08x,%s,%s,0x%08lx)\n",
|
|
|
|
hkey, pszSubkey, pszValue, grfMode);
|
|
|
|
|
|
|
|
return IStream_ConstructorA(hkey, pszSubkey, pszValue, grfMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHOpenRegStreamW [SHLWAPI.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* SHOpenRegStream2W [SHLWAPI.@]
|
1999-03-27 17:15:22 +01:00
|
|
|
*/
|
2000-06-02 01:25:44 +02:00
|
|
|
IStream * WINAPI SHOpenRegStreamW(
|
|
|
|
HKEY hkey,
|
|
|
|
LPCWSTR pszSubkey,
|
|
|
|
LPCWSTR pszValue,
|
|
|
|
DWORD grfMode)
|
1999-03-27 17:15:22 +01:00
|
|
|
{
|
2000-06-02 01:25:44 +02:00
|
|
|
TRACE("(0x%08x,%s,%s,0x%08lx)\n",
|
|
|
|
hkey, debugstr_w(pszSubkey), debugstr_w(pszValue), grfMode);
|
|
|
|
|
|
|
|
return IStream_ConstructorW(hkey, pszSubkey, pszValue, grfMode);
|
1999-03-27 17:15:22 +01:00
|
|
|
}
|