title: Get the size of jpeg from memory (converted using GDI++)
body: <p>This is my first post here. I have a problem.
  I need to take a sceenshot of the desktop, convert it to jpeg, store it in a buffer and then manipulate it and send it over the internet.</p>
  
  <p>I have written the code for doing this with GetDC....and GDI+ for converting the HBITMAP to jpeg. The problem I am having now is that I don't know the size of the jpeg that has been saved into the IStream. Here is part of the code that transforms the bitmap referenced by the HBITMAP hBackBitmap into jpeg and save it into pStream. I need to know how many bytes have been written into pStream and how I can use pStream (get a PVOID handle):</p>
  
  <pre><code>Gdiplus::Bitmap bitmap(hBackBitmap, NULL);///loading the HBITMAP
  CLSID clsid;
  GetEncoderClsid(L"image/jpeg", &amp;clsid);
  HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED, nBlockSize) ;//allocating memory, the size of the current bitmap size. i'm over allocating but i don't think there is any way to get the exact ammount I need to allocate, is there?
  if(!hGlobal)
      return;
  IStream* pStream = NULL ;
  if(CreateStreamOnHGlobal(hGlobal, TRUE, &amp;pStream) != S_OK )
      return;
  bitmap.Save(pStream, &amp;clsid);
  </code></pre>
  
  <p>What I need is:
  1. Find out the size of jpeg, how many bytes have been written in the stream
  2. How to use the stream. Can I get a PVOID for the data in stream for example?</p>
  
  <p>Thank you.</p>