Posted on 1998-08-18
Last Modified: 2013-12-03
I have my app to load some BMP's from resources . The problem is that BMP's are really large .. and my EXE is > 3MB . I wonder how could I load JPG and convert it to a HBITMAP or something .. Can anyone help me ?

Question by:WxW
  • 3
  • 2
  • 2

Expert Comment

ID: 1413623
You can, but you have to write some code

Insert file as custom resource into your app, for VC5 do it like this
1. Insert Menu, click Resource...
2. click Import... on the dialog.  
3. Browse the filename and press Import button
4. For resource type type a string e.g. "JPEG" (without the quotes)
If you do this write you get a custom resource called something like IDR_JPEG1 which when you open it up you get a tonne of hex (hex dump of the file)

Now coding
1. Get an HRSRC resource handle using FindResource or FindResourceHandleEx
2. Call LoadResource using the HRSRC to get an HGLOBAL which is the handle to a block of global memory containg the data.
3. Assuming you got this far, GlobalLock to get a pointer to the data
4. Decompress the JPEG into memory (see below)
5. GlobalUnlock the HGLOBAL
Be sure to put error checking in through out, as most of the opps can go wrong if out of memory of called with bad params

To decompress this JPEG into an HBITMAP you need to write code to do this.  Most code I've seen does this files rather than memory.  
You can either adapt this from scratch, or if starting MFC based code override CFile to work on memory (or use CMemFile and Attach it to the RAM)

One site with JPEG code is (haven't tried this one) (check for BITMAP.ZIP near the bottom of the page)

Otherwise you can get the necessary code from Stingray (Objective Toolkit) or Periphere (Weekly MFC) if you don't want to live with the above's licensing rules


Expert Comment

ID: 1413624
At this internet address: 

you can get the freely distributable freeware 'nviewlib.dll' which contains a really simple
API to load multiple file formats(jpg,gif, ...). Try it, i've been using it in a semi-commercial
(in-house) application, and i got no problems yet (about 3/4 year long)

Author Comment

ID: 1413625
I will process both options to see which is best and faster .
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 1413626
I found the dll & lib more effective and useful , please snoegler answer . Answer2000 thanks anyway :)

Expert Comment

ID: 1413627
Well I didn't know about that.  Programming's always better if you can somebody else to write the code for you :-)

Accepted Solution

snoegler earned 20 total points
ID: 1413628
Thanks :)

Author Comment

ID: 1413629
Thanks snoegler also .
Answer2000 : I agree that writing your own code is much much much much more effective and you are "proud" of it . But lemme tell you that my first decision to start such a heavy app with plain C++ and API ( not using MFC or most OWL libraries ) , has allready filled 50000 lines of code and I might need more 50000 . I am a little tired , so I prefer not doing things that others have ready for me ....


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ODBC Connection; Switch between 2 SQL Databases VBA 11 103
SQL Server Express 2014 Master / Slave database replication 4 662
wordpress limitations 4 123
Windows ICD FFU Issue 4 60
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question