Exemplo n.º 1
0
/*************************************************************************
 * SHOpenRegStream2W	[SHLWAPI.@]
 *
 * See SHOpenRegStream2A.
 */
IStream * WINAPI SHOpenRegStream2W(HKEY hKey, LPCWSTR pszSubkey,
                                   LPCWSTR pszValue, DWORD dwMode)
{
  ISHRegStream *tmp;
  HKEY hStrKey = NULL;
  LPBYTE lpBuff = NULL;
  DWORD dwLength = 0;
  LONG ret;

  TRACE("(%p,%s,%s,0x%08x)\n", hKey, debugstr_w(pszSubkey),
        debugstr_w(pszValue), dwMode);

  if (dwMode == STGM_READ)
    ret = RegOpenKeyExW(hKey, pszSubkey, 0, KEY_READ, &hStrKey);
  else /* in write mode we make sure the subkey exits */
    ret = RegCreateKeyExW(hKey, pszSubkey, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &hStrKey, NULL);

  if (ret == ERROR_SUCCESS)
  {
    if (dwMode == STGM_READ || dwMode == STGM_READWRITE)
    {
      /* read initial data */
      ret = RegQueryValueExW(hStrKey, pszValue, 0, 0, 0, &dwLength);
      if (ret == ERROR_SUCCESS && dwLength)
      {
        lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);
        RegQueryValueExW(hStrKey, pszValue, 0, 0, lpBuff, &dwLength);
      }
    }

    if (!dwLength)
      lpBuff = HeapAlloc(GetProcessHeap(), 0, dwLength);

    tmp = IStream_Create(hStrKey, lpBuff, dwLength);
    if(tmp)
    {
      if(pszValue)
      {
        int len = lstrlenW(pszValue) + 1;
        tmp->u.keyNameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
        memcpy(tmp->u.keyNameW, pszValue, len * sizeof(WCHAR));
      }

      tmp->dwMode = dwMode;
      tmp->bUnicode = TRUE;
      return &tmp->IStream_iface;
    }
  }

  HeapFree(GetProcessHeap(), 0, lpBuff);
  if (hStrKey)
    RegCloseKey(hStrKey);
  return NULL;
}
Exemplo n.º 2
0
/*************************************************************************
 * SHCreateStreamWrapper   [SHLWAPI.@]
 *
 * Create an IStream object on a block of memory.
 *
 * PARAMS
 * lpbData    [I] Memory block to create the IStream object on
 * dwDataLen  [I] Length of data block
 * dwReserved [I] Reserved, Must be 0.
 * lppStream  [O] Destination for IStream object
 *
 * RETURNS
 * Success: S_OK. lppStream contains the new IStream object.
 * Failure: E_INVALIDARG, if any parameters are invalid,
 *          E_OUTOFMEMORY if memory allocation fails.
 *
 * NOTES
 *  The stream assumes ownership of the memory passed to it.
 */
HRESULT WINAPI SHCreateStreamWrapper(LPBYTE lpbData, DWORD dwDataLen,
                                     DWORD dwReserved, IStream **lppStream)
{
  ISHRegStream *strm;

  if (lppStream)
    *lppStream = NULL;

  if(dwReserved || !lppStream)
    return E_INVALIDARG;

  strm = IStream_Create(NULL, lpbData, dwDataLen);

  if(!strm)
    return E_OUTOFMEMORY;

  IStream_QueryInterface(&strm->IStream_iface, &IID_IStream, (void**)lppStream);
  IStream_Release(&strm->IStream_iface);
  return S_OK;
}
Exemplo n.º 3
0
/*************************************************************************
 * @   [SHLWAPI.12]
 *
 * Create an IStream object on a block of memory.
 *
 * PARAMS
 * lpbData   [I] Memory block to create the IStream object on
 * dwDataLen [I] Length of data block
 *
 * RETURNS
 * Success: A pointer to the IStream object.
 * Failure: NULL, if any parameters are invalid or an error occurs.
 *
 * NOTES
 *  A copy of the memory pointed to by lpbData is made, and is freed
 *  when the stream is released.
 */
IStream * WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
{
  ISHRegStream *strm = NULL;
  LPBYTE lpbDup;

  TRACE("(%p,%d)\n", lpbData, dwDataLen);

  if (!lpbData)
    dwDataLen = 0;

  lpbDup = HeapAlloc(GetProcessHeap(), 0, dwDataLen);

  if (lpbDup)
  {
    memcpy(lpbDup, lpbData, dwDataLen);
    strm = IStream_Create(NULL, lpbDup, dwDataLen);

    if (!strm)
      HeapFree(GetProcessHeap(), 0, lpbDup);
  }
  return &strm->IStream_iface;
}
Exemplo n.º 4
0
/*************************************************************************
 * @   [SHLWAPI.12]
 *
 * Create an IStream object on a block of memory.
 *
 * PARAMS
 * lpbData   [I] Memory block to create the IStream object on
 * dwDataLen [I] Length of data block
 *
 * RETURNS
 * Success: A pointer to the IStream object.
 * Failure: NULL, if any parameters are invalid or an error occurs.
 *
 * NOTES
 *  A copy of the memory pointed to by lpbData is made, and is freed
 *  when the stream is released.
 */
IStream * WINAPI SHCreateMemStream(const BYTE *lpbData, UINT dwDataLen)
{
  IStream *iStrmRet = NULL;
  LPBYTE lpbDup;

  TRACE("(%p,%d)\n", lpbData, dwDataLen);

  if (!lpbData)
    dwDataLen = 0;

  lpbDup = HeapAlloc(GetProcessHeap(), 0, dwDataLen);

  if (lpbDup)
  {
    memcpy(lpbDup, lpbData, dwDataLen);
    iStrmRet = (IStream *)IStream_Create(NULL, lpbDup, dwDataLen);

    if (!iStrmRet)
      HeapFree(GetProcessHeap(), 0, lpbDup);
  }
  return iStrmRet;
}
Exemplo n.º 5
0
/*************************************************************************
 * SHCreateStreamOnFileEx   [SHLWAPI.@]
 *
 * Create a stream on a file.
 *
 * PARAMS
 *  lpszPath     [I] Path of file to create stream on
 *  dwMode       [I] Mode to create stream in
 *  dwAttributes [I] Attributes of the file
 *  bCreate      [I] Whether to create the file if it doesn't exist
 *  lpTemplate   [I] Reserved, must be NULL
 *  lppStream    [O] Destination for created stream
 *
 * RETURNS
 * Success: S_OK. lppStream contains the new stream object
 * Failure: E_INVALIDARG if any parameter is invalid, or an HRESULT error code
 *
 * NOTES
 *  This function is available in Unicode only.
 */
HRESULT WINAPI SHCreateStreamOnFileEx(LPCWSTR lpszPath, DWORD dwMode,
                                      DWORD dwAttributes, BOOL bCreate,
                                      IStream *lpTemplate, IStream **lppStream)
{
  DWORD dwAccess, dwShare, dwCreate;
  HANDLE hFile;

  TRACE("(%s,%d,0x%08X,%d,%p,%p)\n", debugstr_w(lpszPath), dwMode,
        dwAttributes, bCreate, lpTemplate, lppStream);

  if (!lpszPath || !lppStream || lpTemplate)
    return E_INVALIDARG;

  *lppStream = NULL;

  /* Access */
  switch (STGM_ACCESS_MODE(dwMode))
  {
  case STGM_WRITE:
  case STGM_READWRITE:
    dwAccess = GENERIC_READ|GENERIC_WRITE;
    break;
  case STGM_READ:
    dwAccess = GENERIC_READ;
    break;
  default:
    return E_INVALIDARG;
  }

  /* Sharing */
  switch (STGM_SHARE_MODE(dwMode))
  {
  case 0:
  case STGM_SHARE_DENY_NONE:
    dwShare = FILE_SHARE_READ|FILE_SHARE_WRITE;
    break;
  case STGM_SHARE_DENY_READ:
    dwShare = FILE_SHARE_WRITE;
    break;
  case STGM_SHARE_DENY_WRITE:
    dwShare = FILE_SHARE_READ;
    break;
  case STGM_SHARE_EXCLUSIVE:
    dwShare = 0;
    break;
  default:
    return E_INVALIDARG;
  }

  switch(STGM_CREATE_MODE(dwMode))
  {
  case STGM_FAILIFTHERE:
    dwCreate = bCreate ? CREATE_NEW : OPEN_EXISTING;
    break;
  case STGM_CREATE:
    dwCreate = CREATE_ALWAYS;
    break;
  default:
    return E_INVALIDARG;
  }

  /* Open HANDLE to file */
  hFile = CreateFileW(lpszPath, dwAccess, dwShare, NULL, dwCreate,
                      dwAttributes, 0);

  if(hFile == INVALID_HANDLE_VALUE)
    return HRESULT_FROM_WIN32(GetLastError());

  *lppStream = IStream_Create(lpszPath, hFile, dwMode);

  if(!*lppStream)
  {
    CloseHandle(hFile);
    return E_OUTOFMEMORY;
  }
  return S_OK;
}