flat assembler
Message board for the users of flat assembler.

Index > Windows > won't compile if proc is called

Author
Thread Post new topic Reply to topic
pinny_woman



Joined: 29 Mar 2008
Posts: 9
pinny_woman 30 Mar 2008, 23:04
The code below will compile fine.
However, if I want to make a call to the CreateBM procedure, fasm complains of an invalid value where indicated.

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32axp.inc'

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  RegisterClass,wc
        invoke  CreateWindowEx,WS_EX_CLIENTEDGE,myClass,myTitle,WS_CLIPCHILDREN+WS_VISIBLE+WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320, 240, NULL, NULL, [wc.hInstance],NULL
        mov     [hWndMain], eax
        invoke  ShowWindow, [hWndMain], SW_SHOWDEFAULT
        invoke  UpdateWindow, [hWndMain]
    @@:
  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop
  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc wndProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg], WM_CREATE
        je      .wmCREATE
        cmp     [wmsg], WM_DESTROY
        je      .wmDESTROY
        jmp     .wmDEFAULT
    .wmDEFAULT:
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .wmBYE
    .wmCREATE:
        invoke  LoadBitmap, [wc.hInstance], IDB_IMG
        mov     [ImgHnd], eax
; when the stdcall below is uncommented, it won't compile
;        stdcall CreateBM, [imgHnd]
        xor     eax, eax
        jmp     .wmBYE
    .wmDESTROY:
        invoke  PostQuitMessage,0
        xor     eax,eax
        jmp     .wmBYE
    .wmBYE:
        pop     edi esi ebx
        ret
endp

proc    CreateBM, hbc
        locals

                bm      BITMAP
                hdcMem  dd ?
                hdcMem2 dd ?
                hbmMask dd ?
        endl
;when trying to compile with the above call uncommented, fasm says
;the line below has an invalid value
        invoke  GetObject, [hbc], sizeof.BITMAP, bm
        ret
endp

section '.data' data readable writeable

ImgHnd                  dd ?
hWndMain                dd ?
msg                     MSG
wc                      WNDCLASS 0, wndProc, 0, 0, NULL, NULL, NULL, COLOR_WINDOW+1, NULL, myClass
myClass                 db 'test', 0
myTitle                 db 'test', 0
IDB_IMG                = 3000

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL',\
        gdi32,   'GDI32.DLL',\
        comdlg32,'COMDLG32.DLL',\
        advapi32,'ADVAPI32.DLL',\
        comctl32,'COMCTL32.DLL'

include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
include '%fasminc%\apia\Gdi32.inc'
include '%fasminc%\apia\Comdlg32.inc'
include '%fasminc%\apia\Advapi32.inc'
include '%fasminc%\apia\Comctl32.inc'

section '.rsrc' resource data readable
directory \
        RT_BITMAP, bitmaps

resource bitmaps, \
        IDB_IMG, LANG_ENGLISH+SUBLANG_DEFAULT, ball

bitmap ball, 'img.bmp'
    


I'm completely stuck Confused
Post 30 Mar 2008, 23:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20300
Location: In your JS exploiting you and your system
revolution 31 Mar 2008, 00:54
You need to pass the address of the bm structure. Since it is on the stack you can't pass the address directly, use the addr prefix. Like this:
Code:
        invoke  GetObject, [hbc], sizeof.BITMAP, addr bm    
Post 31 Mar 2008, 00:54
View user's profile Send private message Visit poster's website Reply with quote
pinny_woman



Joined: 29 Mar 2008
Posts: 9
pinny_woman 31 Mar 2008, 00:58
many thanks revolution Smile
Post 31 Mar 2008, 00:58
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.