.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 ?
ThreadID Dword ?
.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?
? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?; your program doesn't process the command line.
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT

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
? ?jmp YaYa
? ? .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
? ? ? ? ? ? ? ? ? ? ?
? ? ? ? invoke PostQuitMessage,NULL? ? ? ? ? ? ? ?
? ? ? ?
? ? .ELSE
? ? ? ? invoke DefWindowProc,hWnd,uMsg,wParam,lParam? ? ?; Default message processing
? ? ? ? ret? ? <<<<<<<<<<< -RET
? ? .ENDIF
? ?
? ?
? ?
? ?
? WndProc endp




? ?
? YaYa:
? ? mov? eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,eax,\
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL,NORMAL_PRIORITY_CLASS,\
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ADDR ThreadID
invoke CloseHandle,eax


? ?ret? <<<<< ----- RET





ThreadProc PROC USES ecx Param:DWORD
?
invoke MessageBox,NULL,ADDR AppName,ADDR AppName,MB_OK

?
? ?



ThreadProc ENDP

end start




The program crashes for no reason at all :(



Im trying to create the thread without having to use a menu like in the tutorial ... WHY does it crash?
Posted on 2005-08-04 18:12:29 by shism2
I don't even see where you call the YaYa label which creates the thread. Can you post your normally please? Also, "it does not work" is not a plausible explanation. Please post the exception information from the crash.
Posted on 2005-08-04 18:22:05 by comrade
1: trace with a debugger and see where the faulting instruction is
2: I've noticed you don't have a "ret" in neither your threadproc nor wndproc. fix it.
3: use the boards CODE tags, or attach a file
Posted on 2005-08-04 18:22:41 by f0dder
Change the jmp YaYa to call YaYa. It may work better without crashing.

Raymond
Posted on 2005-08-04 23:06:56 by Raymond