flat assembler
Message board for the users of flat assembler.

Index > Windows > How to load a bitmap

Author
Thread Post new topic Reply to topic
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
I have this code in c++ that loads a bitmap from a resource. how would I load a bitmap from a resource or a file (don't care which one we can get to work) in fasm

here is the c++ code
Code:
case WM_CREATE:
                {               

                        
                        bmpSource = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_WIN32FORMSAPPLICATION2), IMAGE_BITMAP, 0, 0, 0);
          hdcSource = CreateCompatibleDC(GetDC(0));
          SelectObject(hdcSource, bmpSource);

case WM_PAINT:
                hdc = BeginPaint(hWnd, &ps);
                BitBlt(hdc, 0, 0, 429, 87, hdcSource, 0, 0, SRCCOPY);
          EndPaint(hWnd, &ps);
                        
                break;
    


I tried this but it did not show anything
Code:

.wmcreate:  
invoke GetModuleHandleA,0
invoke LoadImageA,eax, "a.bmp", IMAGE_BITMAP, 0, 0, 0
mov [bmpSource],eax
invoke GetDC,0
invoke CreateCompatibleDC,eax
mov [hdcSource],eax
invoke SelectObject,[hdcSource], [bmpSource]

.wmpaint:
        invoke BeginPaint,[hwnd],ps
        invoke BitBlt, eax,0,0,200,200,[hdcSource],0,0,SRCCOPY
invoke EndPaint,[hwnd],ps  

data
bmpSource dd ?
hdcSource dd ?
ps PAINTSTRUCT <>    
    

thanks
Post 11 Dec 2013, 18:00
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
How does "a.bmp" is described in your RC file?
Does it have a NAME (a string) or an ID?
Post 11 Dec 2013, 18:27
View user's profile Send private message Send e-mail Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
I was trying to just run it from a file because I did not know how to load it in a resource so a.bmp is a file next to the exe
Post 11 Dec 2013, 18:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
Looking at the docs for "LoadImage":
Quote:
lpszName

Identifies the image to load.

If the hinst parameter is non-NULL and the fuLoad parameter does not include LR_LOADFROMFILE, lpszName is a pointer to a null-terminated string that contains the name of the image resource in the hinst module.
So in your case the image must be a resource in the exe file because hinst is non-null and you didn't specify the LR_LOADFROMFILE flag.
Post 11 Dec 2013, 19:05
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
i tried this but it still did not work
invoke LoadImageA,eax, "a.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE
Post 11 Dec 2013, 19:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
What is the error code returned from LoadImage?
Post 11 Dec 2013, 19:51
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
patchariadog wrote:
invoke LoadImageA,eax, "a.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE
MSDN wrote:
hinst [in, optional]

To load a stand-alone resource (icon, cursor, or bitmap file)—for example, c:\myimage.bmp—set this parameter to NULL.
Those who program for Windows without MSDN should be euthanased for mercy's sake. Wink
Post 11 Dec 2013, 20:08
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
You're almost done!
Just use 0 instead of EAX (1st param).
Post 11 Dec 2013, 20:10
View user's profile Send private message Send e-mail Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
this is what I got for the first part now but it still does not show it
Code:
invoke GetModuleHandleA,0
invoke LoadImageA,0, "a.bmp", IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE
mov [bmpSource],eax
invoke GetDC,0
invoke CreateCompatibleDC,eax
mov [hdcSource],eax
invoke SelectObject,[hdcSource], [bmpSource]
    

thanks for the help
Post 11 Dec 2013, 20:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
What are the error codes from each of the API calls?
Post 11 Dec 2013, 21:11
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1419
Location: Toronto, Canada
AsmGuru62
Please use a debugger in this case.
I do not see any issues here, except that "a.bmp" may be not in the current directory.
Try a full path for this file.
Post 11 Dec 2013, 21:26
View user's profile Send private message Send e-mail Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
I tried the full path and it still does not work. how do I check the error codes I am using the fasmw ide
Post 11 Dec 2013, 21:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17671
Location: In your JS exploiting you and your system
revolution
patchariadog wrote:
how do I check the error codes I am using the fasmw ide
Someone already mentioned a debugger. You could try ollydbg. But also just using MessageBox and displaying the returned values can be another option.
Post 11 Dec 2013, 21:40
View user's profile Send private message Visit poster's website Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
how do I use messagebox if it is not crashing I am going to try using getlasterror but I never used this before
Post 11 Dec 2013, 22:30
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog
I wasnt sure if I was suppose to put the getlast error after each line of code or just the last one so here are the results

wm_create
when I did just the last line it says good
when I did all lines all lines say good except the last line says invalid handle

wm_paint
does not give me any messageboxes

I don't know how to read these results so any help would be appreciated.
thanks
Post 11 Dec 2013, 22:43
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 730
tthsqe
patchariadog,
I used bitmap in a 2D game a long time ago. Since the whole thing might be overkill, I included strip.asm that just displays the bitmap. The functions that you should see are Paint, RedoPaint, and CleanupPaint.


Description:
Download
Filename: phoenix.zip
Filesize: 44.35 KB
Downloaded: 66 Time(s)

Post 11 Dec 2013, 23:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.