I've just started to learn assembly using masm32, and following Iczellion's tutorials. The tutorials I have done have worked fine with no problems so far, until now. I've come to the 3rd tutorial which is on making windows, however it doesn't assemble. It is here http://win32assembly.online.fr/tut3.html , and this is the code they give :
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib ; calls to functions in user32.lib and kernel32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.DATA ; initialized data
ClassName db "SimpleWinClass",0 ; the name of our window class
AppName db "Our First Window",0 ; the name of our window
.DATA? ; Uninitialized data
hInstance HINSTANCE ? ; Instance handle of our program
CommandLine LPSTR ?
.CODE ; Here begins our code
start:
invoke GetModuleHandle, NULL ; get the instance handle of our program.
; Under Win32, hmodule==hinstance mov hInstance,eax
mov hInstance,eax
invoke GetCommandLine ; get the command line. You don't have to call this function IF
; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT ; call the main function
invoke ExitProcess, eax ; quit our program. The exit code is returned in eax from WinMain.
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX ; create local variables on stack
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX ; fill values in members of wc
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc ; register our window class
invoke CreateWindowEx,NULL,\
ADDR ClassName,\
ADDR AppName,\
WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
CW_USEDEFAULT,\
NULL,\
NULL,\
hInst,\
NULL
mov hwnd,eax
invoke ShowWindow, hwnd,CmdShow ; display our window on desktop
invoke UpdateWindow, hwnd ; refresh the client area
.WHILE TRUE ; Enter message loop
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam ; return exit code in eax
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY ; if the user closes our window
invoke PostQuitMessage,NULL ; quit our application
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
I get the following errors when trying to assemble with Masm32:
Assembling: D:\w32window.asm
D:\w32window.asm(19) : error A2008: syntax error : hInstance
D:\w32window.asm(20) : error A2008: syntax error : CommandLine
D:\w32window.asm(28) : error A2006: undefined symbol : CommandLine
D:\w32window.asm(28) : error A2114: INVOKE argument type mismatch : argument : 3
D:\w32window.asm(28) : error A2006: undefined symbol : hInstance
D:\w32window.asm(28) : error A2114: INVOKE argument type mismatch : argument : 1
D:\w32window.asm(25) : error A2006: undefined symbol : hInstance
D:\w32window.asm(27) : error A2006: undefined symbol : CommandLine
D:\w32window.asm(39) : error A2006: undefined symbol : null
D:\w32window.asm(40) : error A2006: undefined symbol : null
D:\w32window.asm(41) : error A2006: undefined symbol : hInstance
D:\w32window.asm(48) : error A2006: undefined symbol : HIconSm
I have no idea why this happens, and it's quite annoying because I thought I understood it :/ Any ideas on why this happens?
Thanks. :U
EDIT: Turns out the .data? part should have been:
.data?
hInstance dd ?
CommandLine dd ?
Er, thanks anyway.
hi
i compile this source this works
examine yours bat or cmd
\masm32\bin\ml.exe /c /coff source.asm
\masm32\bin\link.exe /SUBSYSTEM:WINDOWS source.obj
if exist *.obj del *.obj
as example if masm32 in C: \ path is
greets
ragdog
:dazzled: Strange, this only works for me if I change the .data? section to :
.data?
hInstance dd ?
CommandLine dd ?
What's the difference between the two?
Thanks for your fast reply.
in windows.inc it is declared: HINSTANCE typedef DWORD
there it copies the hinstance also into dword more buffer in principle the same
that sees then in such a way from hInstance DWORD ? or you can also hInstance dd ? use
no does not only work then for you
sorry for my english my german it better :bg
Oh right I see, thanks for the help :U