BOOL GetStreamLength (IStream* pStream, ULARGE_INTEGER* puiLength)
{
_ASSERT ((pStream != NULL) && (puiLength != NULL));
BOOL bSuccess = FALSE;
LARGE_INTEGER lMov;
ULARGE_INTEGER ulEnd,ulBegin;
HRESULT hr = S_FALSE;
lMov.QuadPart = 0;
do
{
CComPtr<IStream> spStreamClone;
hr = pStream->Clone (&spStreamClone);
if (FAILED(hr))
break;
hr = spStreamClone->Seek (lMov, STREAM_SEEK_END, &ulEnd);
if (FAILED(hr))
break;
hr = spStreamClone->Seek (lMov, STREAM_SEEK_SET, &ulBegin);
if (FAILED(hr))
break;
puiLength->QuadPart = ulEnd.QuadPart - ulBegin.QuadPart;
bSuccess=TRUE;
}while(FALSE);
return bSuccess;
}
BOOL CreateCompatileStream (SIZE_T dwSize, IStream** ppStream)
{
_ASSERT (dwSize != 0);
BOOL bSuccess = FALSE;
HGLOBAL hGlobal;
hGlobal = ::GlobalAlloc (GPTR, dwSize);
if (hGlobal != NULL)
{
bSuccess = SUCCEEDED (::CreateStreamOnHGlobal (hGlobal, TRUE, ppStream));
}
return bSuccess;
}