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

  • SEARCH
  • Home
  • 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

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Joda Time (as ever) makes this really easy due to… May 12, 2026 at 12:53 pm
  • Editorial Team
    Editorial Team added an answer This is usually because: the target directory doesn't exist the… May 12, 2026 at 12:53 pm
  • Editorial Team
    Editorial Team added an answer I was on the same boat some time ago. My… May 12, 2026 at 12:53 pm

Related Questions

Update : I edited the code, but the problem persists... Hi everyone, this is
I have a problem running a simple Hello-world program in C++ on my Windows
I have a compiled swf file and a I can't edit it , but
Randomly and without warning (or apparent reason), VS 2008 decided to act as if

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.