External vs. internal resources, bitmaps, .EXE size etc.

Posted on 2005-04-13
Last Modified: 2013-11-20
My application currently is an EXE and no external DLL's or anything, pretty simple as far as file structure is concerned. I do however have a bunch of external 24bit bitmap files that are used to build various parts of the user interface, and at this time, I have imported them all into my resource file and when the application compiles, the resulting .EXE is around 6MB.. This I know is going to grow as additional bitmaps are imported in to support UI that I have not yet put in place.

What are my alternatives?  I load the images like this:

  hBmp = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(IDB_BITMAPX), IMAGE_BITMAP, 0, 0, 0);

Everything is working just fine, I'm just concerned that a large EXE might be problematic in the end? I could of course just load the files, and have the bitmaps existing along with the EXE, but I don't want straight-up bitmap files in the application folder, that could be edited or accidentally deleted and what not. Can they be packaged somehow into a DLL or an external resource file?

What do you suggest?

Question by:PMH4514
    LVL 43

    Expert Comment

    Any external files could be edited/deleted.  
    You could package them in resource dll's and load from those.
    However this hack might work.  Have the bitmaps as external files but rename them eg x001.dll, x002.dll and so on.  Now just load them as you would a normal bitmap from an external file.

    Author Comment

    hacks are always nice :)

    how would I go about packaging them in resource dll's?
    LVL 43

    Expert Comment

    Make a regular dll.
    Put the bitmaps into that as you currently do.
    Then when you want a bitmap the code is roughly

    HINSTANCE hInst = LoadLibrary("bitmaps.dll");
      hBmp = (HBITMAP)::LoadImage(hInst, MAKEINTRESOURCE(IDB_BITMAPX), IMAGE_BITMAP, 0, 0, 0);

    Author Comment

    oh so it's just a DLL project with the bitmaps as resources.. looks easy enough, I'll give that a try.

    Is there a reason to avoid a large .EXE by putting them in the DLL though or does it not really matter? (ie. the bitmaps will get loaded anyway)
    LVL 43

    Accepted Solution

    If you have a number of resource dll's then there may be a 'slight' performance gain at startup.  Load exe - 100KB then first resource dll - further 250KB - compared to load exe 20MB.  With multiple resource dll's only the ones required get loaded and then only when required.  A monolithic app has to be read from disk even if a lot isn't going to be of use (I think)

    The main advantage of resource dll's is that they can be language/country dependant.  Same code, same ID but different text/pictures depending on LoadLibrary("CountryA.dll") or LoadLibrary("CountryB.dll")
    You can even go further and just have LoadLibrary("resource.dll") and when you install the product it copies and renames the appropriate dll.

    Author Comment

    Sounds good. Thanks!

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now