Announcement

Collapse
No announcement yet.

LoadImage from resource failure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LoadImage from resource failure

    I've got a bitmap image in my resource file which I want to load into memory by handle, so far I've not met with success, and to make matters annoying, the debugger will crash when encountering the LoadImage line. Tried going the FindResource and LoadResource route, but they also generate a:
    Code:
    Exception: Memory Access Violation
    Program tried to read or write an invalid memory address
    End Debug at 12:47:50 PM on 2/14/2009
    on me. Note: GRAPHIC BITMAP LOAD iName, 20,20 TO hBitmap works just peachy. But is not what I need, I actually need the PALETTE of said image. Also, LoadBitmap fails with the Memory Access Violation as well. Running the program compiled, I get back 0 when using a message box to display the results of the various load attempts.
    Furcadia, an interesting online MMORPG in which you can create and program your own content.

  • #2
    I'm sorry, should be including reference code for what I'm doing.

    In my RC file I have:
    Code:
    IDR_POSITIONTILE    BITMAP DISCARDABLE "images\floor0137.bmp"
    So that in my main program I can:
    Code:
    $POSITIONTILE                   = "IDR_POSITIONTILE"
    And then I'm supposed to be able to load it with:
    Code:
    LOCAL iName AS ASCIIZ * 80
    LOCAL hBitmap, fResource, hResource, lResource AS DWORD
    iName = $POSITIONTILE
    GRAPHIC BITMAP LOAD iName, 20,20 TO hBitmap
    MSGBOX "Graphic Bitmap Load Success = "& FORMAT$(hBitmap)
    ' returns the ID for the Graphic Control
    
    hBitmap = LoadImage(CB.HNDL, iName, %IMAGE_BITMAP, 0, 0, %LR_CREATEDIBSECTION)
    ' dies in debugger
    
    MSGBOX "Load Image Success = "& FORMAT$(hBitmap)
    ' returns 0 in compiled
    
    hBitmap = LoadBitmap(CB.HNDL, iName)
    ' dies in debugger
    
    MSGBOX "Load Bitmap Success = "& FORMAT$(hBitmap)
    ' returns 0 in compiled
    
    fResource = FindResource(0, iName, BYVAL %RT_BITMAP)
    IF ISTRUE fResource THEN
        hResource = LoadResource(CB.HNDL, fResource)
        ' dies in debugger
    
        MSGBOX "Load Resource Success " & FORMAT$(hResource)
        ' a duh on fResource, ISTRUE permitted entry to this point
        ' returns 0 in compiled
    
        IF ISTRUE hResource THEN
        END IF
    END IF
    Furcadia, an interesting online MMORPG in which you can create and program your own content.

    Comment


    • #3
      CB.HNDL ??

      You'll need the instance handle.
      Use WINMAIN instead of PBMAIN to get the hInstance handle.
      hellobasic

      Comment


      • #4
        Originally posted by Edwin Knoppert View Post
        CB.HNDL ??

        You'll need the instance handle.
        Use WINMAIN instead of PBMAIN to get the hInstance handle.
        or getmodulehandle(byval 0)?

        Comment


        • #5
          Or use GetModuleHandle("") instead of CB.HNDL.
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            Thank you.
            I just knew I was overlooking something terribly simple.
            Furcadia, an interesting online MMORPG in which you can create and program your own content.

            Comment


            • #7
              thx,Is required.
              :guitar:Shuai,my beloved wife!

              Comment


              • #8
                This is a good demo for, "always test the success of an operation e.g., (hBitmap <> %NULL) and stop executing after something has failed."

                Continuing after an error is how GPFs happen.

                The original code in post #1 tested (Good!) but didn't stop when a failure occurred (GPF!)
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Michael, the GPF was occurring when the attempt was being made to gain a handle for the resource, initially, when writing the chunk of code, I was using the wrong value to the API to get a handle for the resource, so it died on the API call itself while in the debugger, no means to test validity. In the runtime, there was checks for validity, however, I stripped them all out in constructing my test scenerio.
                  Furcadia, an interesting online MMORPG in which you can create and program your own content.

                  Comment

                  Working...
                  X