I'm quite sorry if this is a really obvious error, but I have been working on it for some time, and while I think I finally have most of the win32 issues that were confusing me worked out, I still can't seem to figure out what's going on with this little issue of mine.
I have a little window program that I want to have two buttons and a menu on. I haven't gotten it to compile so I'm not sure about my logic, but I'm just trying to understand win32 programming right now.
My problem is that when I compile FASM gives me the following error:
Error: undefined symbol
Instruction:
main_menu dd RVA data?0005D8B,size?0005D8B,0,0
The code referenced is line 219 of the following:
include '%fasminc%\win32axp.inc'
IDM_MSGPOP = 101
IDM_EXIT = 102
.data
_message_text db 'This is my Message!',0
_message_title db 'My Message',0
_title db 'First Win32Program',0
_about_text db 'This is a simple program to help me',\
' understand win32 programming',0
_btn_text db 'Give me a Message',0
_btn_cncl db 'Cancel',0
_class db 'FASMWIN32',0
_btn_style db 'BS_PUSHBUTTON',0
_btn_dstyle db 'BS_DEFPUSHBUTTON',0
mainhwnd dd ?
hinstance dd ?
btnKhwnd dd ?
btnChwnd dd ?
msg MSG
wc WNDCLASS
.code
start:
; Get hinstance
push NULL
call [GetModuleHandle]
mov [hinstance],eax
; get Application Icon
push IDI_APPLICATION
push NULL
call [LoadIcon]
mov [wc.hIcon],eax
; get cursor
push IDC_ARROW
push NULL
call [LoadCursor]
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_BTNFACE+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],_class
push wc
call [RegisterClass]
; load Menu to eax
push 1000
push [hinstance]
call [LoadMenu]
; Create Main Window with Menu from eax
push NULL
push [hinstance]
push eax
push NULL
push 192
push 192
push 128
push 128
push WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU
push _title
push _class
push 0
call [CreateWindowEx]
mov [mainhwnd],eax
; Refresh Window
push SW_SHOW
push [mainhwnd]
call [ShowWindow]
push [mainhwnd]
call [UpdateWindow]
msg_loop:
push 0
push 0
push NULL
push msg
call [GetMessage]
or eax,eax
jz end_loop
push msg
call [TranslateMessage]
push msg
call [DispatchMessage]
jmp msg_loop
end_loop:
push [msg.wParam]
call [ExitProcess]
proc WindowProc, hwnd,wmsg,wparam,lparam
push ebx esi edi
cmp [wmsg],WM_CREATE
je wmcreate
cmp [wmsg],WM_COMMAND
je wmcommand
cmp [wmsg],WM_DESTROY
je wmdestroy
defwndproc:
push [lparam]
push [wparam]
push [wmsg]
push [hwnd]
call [DefWindowProc]
jmp finish
wmcreate:
; Create Message Button
push NULL
push [hinstance]
push NULL
push [mainhwnd]
push 30
push 50
push 90
push 10
push _btn_text
push _btn_dstyle
push 0
call [CreateWindowEx]
mov [btnKhwnd],eax
or eax,eax
jz failed
; Create Cancel Button
push NULL
push [hinstance]
push NULL
push [mainhwnd]
push 30
push 40
push 90
push 70
push _btn_text
push _btn_dstyle
push 0
call [CreateWindowEx]
mov [btnChwnd],eax
or eax,eax
jz failed
xor eax,eax
jmp finish
failed:
or eax,-1
jmp finish
wmcommand:
mov eax,[lparam]
cmp eax,[hwnd]
je menucom
cmp eax,[btnKhwnd]
je btnK
cmp eax,[btnChwnd]
je btnC
menucom:
mov eax,[wparam]
and eax,0FFFFh
cmp eax,IDM_MSGPOP
je msgpopup
cmp eax,IDM_EXIT
je wmdestroy
btnK:
mov eax,[wparam]
cmp eax,BN_CLICKED
je msgpopup
cmp eax,BN_DBLCLK
je msgpopup
btnC:
mov eax,[wparam]
cmp eax,BN_CLICKED
je wmdestroy
cmp eax,BN_DBLCLK
je wmdestroy
msgpopup:
push MB_OK
push _message_title
push _message_text
push [hwnd]
call [MessageBox]
jmp finish
wmdestroy:
push [btnKhwnd]
call [DeleteObject]
push [btnChwnd]
call [DeleteObject]
push 0
call [PostQuitMessage]
xor eax,eax
finish:
pop edi esi ebx
return
endp
.end start
section '.rsrc' data resource readable
directory RT_MENU, menus
resource menus, \
1000,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu
menu main_menu
menuitem '&Message',0,MFR_POPUP
menuitem '&Display',IDM_MSGPOP,0
menuseparator
menuitem 'E&xit',IDM_EXIT,MFR_END
If anyone can provide help on this error I would greatly appreciate it. I find win32 programming to be rather unintuitive.