MFC - Trying to load a picture from memory using Istream
-
I am trying to load a picture from memory from inspection can you see why this dosen't work? here is part of the class I am using: BOOL CPicture::Load(IStream* pstm) { Free(); HRESULT hr = OleLoadPicture(pstm, 0, FALSE, IID_IPicture, (void**)&m_spIPicture); return hr == S_OK; } here is some code I have found to implement this: ifstream file ("c:\\1.jpg", ios::in|ios::binary|ios::ate); if (file.is_open()) { size = file.tellg(); memblock = new char [size]; file.seekg (0, ios::beg); file.read (memblock, size); file.close(); IStream *pStrm = NULL; HGLOBAL hgbl = GlobalAlloc (0, 852); CreateStreamOnHGlobal (hgbl, true, &pStrm); pStrm->Write(memblock, size, 0); delete [] memblock; m_pict.Load(pStrm); } Thabk you your help will be much appreciated Simon
-
I am trying to load a picture from memory from inspection can you see why this dosen't work? here is part of the class I am using: BOOL CPicture::Load(IStream* pstm) { Free(); HRESULT hr = OleLoadPicture(pstm, 0, FALSE, IID_IPicture, (void**)&m_spIPicture); return hr == S_OK; } here is some code I have found to implement this: ifstream file ("c:\\1.jpg", ios::in|ios::binary|ios::ate); if (file.is_open()) { size = file.tellg(); memblock = new char [size]; file.seekg (0, ios::beg); file.read (memblock, size); file.close(); IStream *pStrm = NULL; HGLOBAL hgbl = GlobalAlloc (0, 852); CreateStreamOnHGlobal (hgbl, true, &pStrm); pStrm->Write(memblock, size, 0); delete [] memblock; m_pict.Load(pStrm); } Thabk you your help will be much appreciated Simon
simon alec smith wrote:
from inspection can you see why this dosen't work?
Not really, unless you explain what you mean by "doesn't work"; such a statement does not help in understanding what your problem is. Does your program crash, throw an exception, paint the image upside down, etc.?
It's time for a new signature.
-
simon alec smith wrote:
from inspection can you see why this dosen't work?
Not really, unless you explain what you mean by "doesn't work"; such a statement does not help in understanding what your problem is. Does your program crash, throw an exception, paint the image upside down, etc.?
It's time for a new signature.
This is what was reported, File c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h line 622 expression: p!= 0
-
This is what was reported, File c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h line 622 expression: p!= 0