Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC - Trying to load a picture from memory using Istream

MFC - Trying to load a picture from memory using Istream

Scheduled Pinned Locked Moved C / C++ / MFC
c++iosperformancehelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simon alec smith
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • S simon alec smith

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • L Lost User

        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.

        S Offline
        S Offline
        simon alec smith
        wrote on last edited by
        #3

        This is what was reported, File c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h line 622 expression: p!= 0

        L 1 Reply Last reply
        0
        • S simon alec smith

          This is what was reported, File c:\program files\microsoft visual studio\vc98\atl\include\atlbase.h line 622 expression: p!= 0

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          simon alec smith wrote:

          expression: p!= 0

          And how does this relate to your code, where does the stack history point to in your program?

          It's time for a new signature.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups