Like Tree1Likes
  • 1 Post By SMurf

LoadBitmap requires GetModuleHandle(NULL) as argument instead of hInstance

This is a discussion on LoadBitmap requires GetModuleHandle(NULL) as argument instead of hInstance within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I was playing around with LoadBitmap. Originally I got it working. Then the screen it load was "white" meaning ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    27

    LoadBitmap requires GetModuleHandle(NULL) as argument instead of hInstance

    Hello,
    I was playing around with LoadBitmap. Originally I got it working. Then the screen it load was "white" meaning the HBITMAP it returned was not NULL, but it was just as if nothing is displayed. I was moving the LoadBitmap back and forth between InitInstance (before and after createWindow routine) and WM_CREATE. Magically when I finally got it working again but only after I replace it get GetModuleHandle(NULL) as the argument instead of hInstance.

    Code:
     hbitmapTest= (HBITMAP)LoadBitmap(GetModuleHandle(NULL), _T("MyBitmap"));
    Question 1: Why does LoadBitmap needs this argument instead of hInstead? I looked online and it says GetModuleHandle returns a module. Looking at the module, it seems it's some sort of dll.

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,259
    If you are loading a bitmap resource, LoadBitmap needs to know from which memory-resident module you want to load it from.

    A module is any PE image (.exe, dll).

    If for example you make a program with a bitmap resource, you will need to pass the handle to the program's module.

    GetModuleHandle(NULL) gets the executable's handle.

    I can't tell you why the hInstance supplied by MFC doesn't work, just looking at it shocked me with so many catches and almost-good things that I ignored this framework entirely and did a few months of booze and hookers instead. Just as fulfilling, if not moreso.
    gardhr likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cl : Command line error D8004 : '/W' requires an argument
    By kakayoma in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2009, 06:09 AM
  2. Replies: 3
    Last Post: 12-01-2005, 06:38 PM
  3. GetModuleHandle (NULL) vs hInstance
    By Lionmane in forum Windows Programming
    Replies: 2
    Last Post: 10-05-2005, 01:33 AM
  4. GetModuleHandle
    By ElWhapo in forum Windows Programming
    Replies: 2
    Last Post: 04-25-2005, 07:15 AM
  5. getting an hinstance
    By voodoomagic in forum Windows Programming
    Replies: 2
    Last Post: 12-11-2004, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21