本文整理汇总了C++中IStream类的典型用法代码示例。如果您正苦于以下问题:C++ IStream类的具体用法?C++ IStream怎么用?C++ IStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateFile
bool CLotteryDlg::_loadPic(CString strFullPath, PicInfo* picInfo)
{
try
{
HANDLE hFile = CreateFile(strFullPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
return false;
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (-1 == dwFileSize)
return false;
picInfo->_hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
if (picInfo->_hGlobal == NULL)
return false;
void * pImageMemory = GlobalLock(picInfo->_hGlobal);
DWORD dwReadedSize;//保存实际读取的文件的大小
ReadFile(hFile, pImageMemory, dwFileSize, &dwReadedSize, NULL);
GlobalUnlock(picInfo->_hGlobal);
CloseHandle(hFile);
IStream* pIStream;//创建一个ISTream接口指针,保存图片流
IPicture* pIPicture;//创建一个IPicture接口指针,表示图片对象
if (S_OK != CreateStreamOnHGlobal(picInfo->_hGlobal, false, &pIStream))//用全局内存初始化IStream接口指针
return false;
if (S_OK != OleLoadPicture(pIStream, 0, false, IID_IPicture, (LPVOID*)&(pIPicture)))//用OleLoadPicture获得IPicture接口指针
{
::GlobalFree(picInfo->_hGlobal);
pIStream->Release();
return false;
}
//得到IPicture COM接口对象后,就可以进行获得图片信息,显示图片等操作
pIPicture->get_Width(&picInfo->_cx);
pIPicture->get_Height(&picInfo->_cy);
picInfo->_iStream = pIStream;
picInfo->_iPic = pIPicture;
picInfo->_x = picInfo->_y = 0;
picInfo->_strFilePath = strFullPath;
}
catch (...)
{
return false;
}
return true;
}
示例2: GlobalAlloc
IPicture* CEnBitmap::LoadFromBuffer(BYTE* pBuff, int nSize)
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
void* pData = GlobalLock(hGlobal);
memcpy2(pData, pBuff, nSize);
GlobalUnlock(hGlobal);
IStream* pStream = NULL;
IPicture* pPicture = NULL;
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&pPicture);
pStream->Release();
}
return pPicture; // caller releases
}
示例3: SavePropertyStoreToString
HRESULT SavePropertyStoreToString(IPropertyStore *pps, PWSTR *ppszBase64)
{
*ppszBase64 = NULL;
IStream *pstm;
HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pstm);
if (SUCCEEDED(hr))
{
hr = SavePropertyStoreToStream(pps, pstm);
if (SUCCEEDED(hr))
{
IStream_Reset(pstm);
hr = GetBase64StringFromStream(pstm, ppszBase64);
}
pstm->Release();
}
return hr;
}
示例4: WriteFileHelper
bool FileStorage::SaveFile(FileEntry& fileEntry, const IStream& sourceStream)
{
IStream* stream = WriteFileHelper(fileEntry, FileOpenMode::DestoryWriteOrCreate, FileDataType::Binary);
RETURN_FALSE_IF_NULL(stream);
sourceStream.CopyTo(*stream);
SAFE_RELEASE(stream);
return true;
}
示例5: LoadGdiplusImage
inline void LoadGdiplusImage(const void *mem, size_t len, const FuncT &func)
{
HGLOBAL hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, len);
void *pData = ::GlobalLock(hGlobal);
memcpy(pData, mem, len);
::GlobalUnlock(hGlobal);
IStream *pStream = NULL;
if( ::CreateStreamOnHGlobal(hGlobal,TRUE, &pStream) == S_OK )
{
std::auto_ptr<Bitmap> bm(Bitmap::FromStream(pStream));
func(bm.get());
pStream->Release();
}
::GlobalFree(hGlobal);
}
示例6: ASSERT
BOOL GdiPlusPicDrawer::CreateImageFromHGlobal(HGLOBAL hBuffer)
{
ASSERT(hBuffer != NULL);
IStream* pStream = NULL;
if (::CreateStreamOnHGlobal(hBuffer, FALSE, &pStream) == S_OK)
{
m_pImage = Gdiplus::Bitmap::FromStream(pStream);
Status lastStatus = m_pImage->GetLastStatus();
pStream->Release();
if (m_pImage != NULL && lastStatus == Ok)
return TRUE;
TRACE(_T("@1 GdiPlusPicDrawer::CreateImageFromHGlobal. Bitmap::FromStream failed :%d\r\n"), lastStatus);
}
else
TRACE(_T("@1 GdiPlusPicDrawer::CreateImageFromHGlobal. CreateStreamOnHGlobal failed\r\n"));
Destroy();
return FALSE;
}
示例7: applyPatchfile
void applyPatchfile(string fname) {
IStream *f = new IFStream(fname);
Injectable_IStream f2(*f);
if (((IFStream*)f)->bad()) {
fprintf(stderr, "file is missing: %s\n", fname.c_str());
exit(1);
}
unsigned type = determine_filetype(f2);
delete f;
switch (type) {
case GZIP: f = new GZ_IFStream(fname); break;
case BZIP2: f = new BZ_IFStream(fname); break;
case DTU: f = new IFStream(fname); break;
case UNKNOWN_FMT: fprintf(stderr, "cannot read file %s\n", fname.c_str()); exit(1);
case TARBALL :
f = new IFStream(fname);
unsigned zero_count;
zero_count = 0;
char tarheader[512];
do {
f->read(tarheader, 512);
if (tarheader[0]==0) ++zero_count;
int size = read_ascii_octal(tarheader+124);
if (size) {
string fileName = getTmpFilename();
{
OFStream o(fileName);
copy_bytes_to_file(*f, o, size);
}
applyPatchfile(fileName);
doneTmpFile(fileName);
unsigned lastblocksize = size % 512;
if (lastblocksize==0) lastblocksize=512;
f->read(tarheader, 512 - lastblocksize);
}
} while (zero_count < 2);
return;
}
Injectable_IStream infile(*f);
type = determine_filetype(infile);
if (type==DTU) patchPackage(infile); else
applyPatchfile(infile);
}
示例8: StopStreaming
HRESULT CWavDestFilter::StopStreaming()
{
IStream* pStream;
if (m_pOutput->IsConnected() == FALSE) {
return E_FAIL;
}
IPin* pDwnstrmInputPin = m_pOutput->GetConnected();
if (!pDwnstrmInputPin) {
return E_FAIL;
}
HRESULT hr = ((IMemInputPin*) pDwnstrmInputPin)->QueryInterface(IID_IStream, (void**)&pStream);
if (SUCCEEDED(hr)) {
BYTE* pb = (BYTE*)_alloca(m_cbHeader);
RIFFLIST* pRiffWave = (RIFFLIST*)pb;
RIFFCHUNK* pRiffFmt = (RIFFCHUNK*)(pRiffWave + 1);
RIFFCHUNK* pRiffData = (RIFFCHUNK*)(((BYTE*)(pRiffFmt + 1)) + m_pInput->CurrentMediaType().FormatLength());
pRiffData->fcc = FCC('data');
pRiffData->cb = m_cbWavData;
pRiffFmt->fcc = FCC('fmt ');
pRiffFmt->cb = m_pInput->CurrentMediaType().FormatLength();
CopyMemory(pRiffFmt + 1, m_pInput->CurrentMediaType().Format(), pRiffFmt->cb);
pRiffWave->fcc = FCC('RIFF');
pRiffWave->cb = m_cbWavData + m_cbHeader - sizeof(RIFFCHUNK);
pRiffWave->fccListType = FCC('WAVE');
LARGE_INTEGER li;
ZeroMemory(&li, sizeof(li));
hr = pStream->Seek(li, STREAM_SEEK_SET, 0);
if (SUCCEEDED(hr)) {
hr = pStream->Write(pb, m_cbHeader, 0);
}
pStream->Release();
}
return hr;
}
示例9: NewGUI_ExtractVistaIcon
bool NewGUI_ExtractVistaIcon(const std::vector<BYTE>& v, Bitmap** pOutBmp)
{
if(pOutBmp == NULL) { ASSERT(FALSE); return false; }
*pOutBmp = NULL;
const size_t SizeICONDIR = 6;
const size_t SizeICONDIRENTRY = 16;
if(v.size() < SizeICONDIR) { ASSERT(FALSE); return false; }
const size_t cImages = *(WORD *)&v[4];
for(size_t i = 0; i < cImages; ++i)
{
const BYTE bWidth = v[SizeICONDIR + (i * SizeICONDIRENTRY)];
const BYTE bHeight = v[SizeICONDIR + (i * SizeICONDIRENTRY) + 1];
const WORD wBitCount = *(WORD *)&v[SizeICONDIR + (i *
SizeICONDIRENTRY) + 6];
if((bWidth == 0) && (bHeight == 0) && (wBitCount == 32))
{
const size_t uSize = *(size_t *)&v[SizeICONDIR + (i *
SizeICONDIRENTRY) + 8];
const size_t uOffset = *(size_t *)&v[SizeICONDIR + (i *
SizeICONDIRENTRY) + 12];
IStream* pStream = NULL;
if(FAILED(CreateStreamOnHGlobal(NULL, TRUE, &pStream))) { ASSERT(FALSE); return false; }
if(pStream == NULL) { ASSERT(FALSE); return false; }
VERIFY(SUCCEEDED(pStream->Write(&v[uOffset],
static_cast<ULONG>(uSize), NULL)));
LARGE_INTEGER liMove;
ZeroMemory(&liMove, sizeof(LARGE_INTEGER));
VERIFY(SUCCEEDED(pStream->Seek(liMove, STREAM_SEEK_SET, NULL)));
*pOutBmp = Bitmap::FromStream(pStream, FALSE);
pStream->Release();
return (*pOutBmp != NULL);
}
}
return false;
}
示例10: NewGUI_SaveIcon
std::vector<BYTE> NewGUI_SaveIcon(HICON hIcon)
{
std::vector<BYTE> v;
if(hIcon == NULL) { ASSERT(FALSE); return v; }
IStream* pStream = NULL;
if(FAILED(CreateStreamOnHGlobal(NULL, TRUE, &pStream))) { ASSERT(FALSE); return v; }
if(pStream == NULL) { ASSERT(FALSE); return v; }
PICTDESC pd;
ZeroMemory(&pd, sizeof(PICTDESC));
pd.cbSizeofstruct = sizeof(PICTDESC);
pd.picType = PICTYPE_ICON;
pd.icon.hicon = hIcon;
IPicture* pPic = NULL;
LONG lSize = 0;
bool bPic = SUCCEEDED(OleCreatePictureIndirect(&pd, IID_IPicture,
FALSE, (LPVOID *)&pPic));
bPic &= (pPic != NULL);
if(bPic)
{
if(SUCCEEDED(pPic->SaveAsFile(pStream, TRUE, &lSize)))
{
LARGE_INTEGER liMove;
ZeroMemory(&liMove, sizeof(LARGE_INTEGER));
VERIFY(SUCCEEDED(pStream->Seek(liMove, STREAM_SEEK_SET, NULL)));
v.resize(static_cast<size_t>(lSize));
ULONG cbRead = 0;
VERIFY(SUCCEEDED(pStream->Read(&v[0], static_cast<ULONG>(
lSize), &cbRead)));
if(cbRead == static_cast<ULONG>(lSize)) { } // Success
else { ASSERT(FALSE); v.clear(); }
}
pPic->Release();
}
pStream->Release();
return v;
}
示例11: ShowJpeg
HRESULT CPicStatic::ShowJpeg(LPVOID picData,DWORD dwFileSize,int x, int y,CDC *pDC)
{
IStream *pStm;
IPicture *pPic;
BOOL bResult;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
LPVOID pvData = NULL;
if (hGlobal == NULL)
return false;
pvData = GlobalLock(hGlobal);
if ( pvData == NULL)
return false;
memcpy(pvData,picData,dwFileSize);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
bResult=OleLoadPicture(pStm,dwFileSize,TRUE,IID_IPicture,(LPVOID*)&pPic);
if(FAILED(bResult))
{
// CloseHandle(hFile);
return false;
}
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
//将图形输出到屏幕上(有点像BitBlt)
bResult=pPic->Render(pDC->m_hDC,0,0,x,y,0,hmHeight,hmWidth,-hmHeight,NULL);
// CloseHandle(hFile);
pStm->Release();
pPic->Release();
if (SUCCEEDED(bResult))
{
return S_OK;
}
else
{
return E_FAIL;
}
}
示例12: ReleasePeer
void CInProcPlugHole::ReleasePeer()
{
if (m_piMarshalledPeer != NULL)
{
IStream* piStream = m_piMarshalledPeer;
m_piMarshalledPeer = NULL;
m_dwVMStarterId = 0;
::ResetEvent(m_hPeerAvailable);
m_mapPeers.clear();
// Unmarshall it one last time to release it
LARGE_INTEGER pos;
pos.QuadPart = 0;
piStream->Seek(pos, STREAM_SEEK_SET, NULL);
IIPDolphinPtr piPeer;
HRESULT hr = ::CoGetInterfaceAndReleaseStream(piStream, __uuidof(IIPDolphin), reinterpret_cast<void**>(&piPeer));
}
}
示例13: GlobalAlloc
//-----------------------------------------------------------------------------
// Does: Read The Picture Data From a Source (File / Resource)
// ~~~~ And Load It Into The Current IPicture Object In Use
//
// InPut: Buffer Of Data Source (File / Resource) And Its Size
// ~~~~~
//
// OutPut: Feed The IPicture Object With The Picture Data
// ~~~~~~ (Use Draw Functions To Show It On a Device Context)
// TRUE If Succeeded...
//-----------------------------------------------------------------------------
BOOL CPicViewer::LoadPictureData(BYTE *pBuffer, int nSize)
//=============================================================================
{
BOOL bResult = FALSE;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
if(hGlobal == NULL)
{
TRACE( "Can not allocate enough memory\n" );
// HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
// MessageBoxEx(hWnd, "Can not allocate enough memory\t", ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
return(FALSE);
}
void* pData = GlobalLock(hGlobal);
memcpy(pData, pBuffer, nSize);
GlobalUnlock(hGlobal);
IStream* pStream = NULL;
if(CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
HRESULT hr;
if((hr = OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_IPicture)) == E_NOINTERFACE)
{
TRACE( "IPicture interface is not supported\n" );
// HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
// MessageBoxEx(hWnd, "IPicture interface is not supported\t", ERROR_TITLE, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
return(FALSE);
}
else // S_OK
{
pStream->Release();
pStream = NULL;
bResult = TRUE;
}
}
FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
return(bResult);
}
示例14: assert
BOOL CDuiImgX::LoadFromMemory( LPVOID pBuf,DWORD dwSize )
{
assert(m_pImg==NULL);
HGLOBAL hMem = ::GlobalAlloc(GMEM_FIXED, dwSize);
BYTE* pMem = (BYTE*)::GlobalLock(hMem);
memcpy(pMem, pBuf, dwSize);
IStream* pStm = NULL;
::CreateStreamOnHGlobal(hMem, TRUE, &pStm);
m_pImg = Gdiplus::Image::FromStream(pStm);
pStm->Release();
::GlobalUnlock(hMem);
// GlobalFree(hMem);
return m_pImg!=NULL;
}
示例15: GetImageFromBase64
Bitmap* GetImageFromBase64(string encodedImage)
{
int imageSize = int((encodedImage.length()/3)+1)*4;
char* t=new char[imageSize];
base64_decode(encodedImage.c_str(),encodedImage.length(), t, &imageSize); // using the base64
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
LPVOID pImage = ::GlobalLock(hMem);
memcpy(pImage, t, imageSize);
IStream* pStream = NULL;
::CreateStreamOnHGlobal(hMem, FALSE, &pStream);
Bitmap *img = new Bitmap(pStream);
pStream->Release();
GlobalUnlock(hMem);
GlobalFree(hMem);
delete []t;
return img;
}