Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 261939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:28:26+00:00 2026-05-11T22:28:26+00:00

This is my first post here. I have a problem. I need to take

  • 0

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.

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):

Gdiplus::Bitmap bitmap(hBackBitmap, NULL);///loading the HBITMAP
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &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, &pStream) != S_OK )
    return;
bitmap.Save(pStream, &clsid);

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?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:28:27+00:00Added an answer on May 11, 2026 at 10:28 pm

    According to the CreateStreamOnHGlobal documentation, your use of it is incorrent. Quote:

    The current contents of the memory block are undisturbed by the creation of the new stream object. Thus, you can use this function to open an existing stream in memory.
    The initial size of the stream is the size of the memory handle returned by the GlobalSize function.

    Therefore, you should replace nBlockSize with 0 to allocate an zero-sized buffer. As the memory buffer must be moveable, you’ll also need to replace GMEM_FIXED with GMEM_MOVEABLE:

    HGLOBAL gGlobal = GlobalAlloc(GMEM_MOVEABLE, 0);
    

    After saving to the stream, the resulting size will be available as

    size_t size = GlobalSize(hGlobal);
    

    To access the JPEG encoded data, you’ll need to use GlobalLock to get a pointer to the actual location in memory.

    Note that Global and Local functions are marked as deprecated and should not be used anymore, but I don’t know a better IStream implementation for your needs without crawling the MSDN documentation. Perhaps somebody else can help here!?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time to post here. I have a problem on my
Well, this is my first post here and really enjoying the site. I have
This is my first post here and I wanted to get some input from
this is my first post here! I'm trying to make a windows forms program
Hi this is my first post here hope you all are well. So Im
This is my first post, have been a lurker for a long time, so
I have a major problem getting this to work properly. Here is the deal.
This is my first post and I'm quite a novice on C++ and compiling
problem euler #5 i found the solution but i don't know why this first
this is my first question to stackoverflow so here it goes... I use cruise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.