Hi there!

I am a Win32 programmer and work actually with C. However, the power of assembly grabbed my intrests on creating some applications with assemblers and Win32. I have a simple beginners question for now which actually is hated all over the programming boards :) Why doesn't the following code work? I just tried to put the the third Win32 tutorial of Iczelion in a more proper kind of code base, making a managable skeleton program. However my skeleton program seems to be entering some kind of loop somewhere which crashes it

Here is the code and thanks to all of you

.386
.MODEL FLAT, STDCALL

option casemap:none

;; INCLUDES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; DECLARATIONS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
InitInstance PROTO :DWORD,:DWORD
RegisterWindowClasses PROTO :DWORD

MainFrame_Create PROTO :DWORD
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

.CONST

.DATA
ClassName DB "Fractus MainFrame Window Class",0
ClassTitle DB "Fractus MainFrame Window Title",0

.DATA?
hInst HINSTANCE ?
lpstrCmdLine LPSTR ?

.CODE

fractus:
INVOKE GetModuleHandle, NULL
MOV hInst, eax

INVOKE GetCommandLine
MOV lpstrCmdLine, eax

INVOKE WinMain, hInst, NULL, lpstrCmdLine, SW_SHOWDEFAULT

INVOKE ExitProcess, eax

WinMain PROC hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpstrCommandLine:LPSTR, dwCmdShow:DWORD
LOCAL msg:MSG

INVOKE InitInstance, hInstance, dwCmdShow

.WHILE TRUE
INVOKE GetMessage, ADDR msg, NULL, 0, 0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW

MOV eax, msg.wParam
RET
WinMain ENDP

InitInstance PROC hInstance:HINSTANCE, dwCmdShow:DWORD
LOCAL hWnd:HWND

INVOKE RegisterWindowClasses, hInstance

INVOKE MainFrame_Create, hInstance

MOV hWnd, eax

INVOKE ShowWindow, hWnd, dwCmdShow
INVOKE UpdateWindow, hWnd
InitInstance ENDP

RegisterWindowClasses PROC hInstance:HINSTANCE
LOCAL wcEx:WNDCLASSEX

MOV wcEx.cbSize, SIZEOF WNDCLASSEX
MOV wcEx.style, CS_HREDRAW or CS_VREDRAW
MOV wcEx.lpfnWndProc, OFFSET MainFrame_WndProc
MOV wcEx.cbClsExtra, NULL
MOV wcEx.cbWndExtra, NULL
PUSH hInstance
POP wcEx.hInstance
MOV wcEx.hbrBackground, COLOR_WINDOW+1
MOV wcEx.lpszMenuName, NULL
MOV wcEx.lpszClassName, OFFSET ClassName
INVOKE LoadIcon, NULL, IDI_APPLICATION
MOV wcEx.hIcon, eax
MOV wcEx.hIconSm, eax
INVOKE LoadCursor, NULL, IDC_ARROW
MOV wcEx.hCursor, eax

INVOKE RegisterClassEx, ADDR wcEx

RET
RegisterWindowClasses ENDP

MainFrame_Create PROC hInstance:HINSTANCE
INVOKE CreateWindowEx, NULL, ADDR ClassName, ADDR ClassTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL

RET
MainFrame_Create ENDP

MainFrame_WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
INVOKE PostQuitMessage, NULL
.ELSE
INVOKE DefWindowProc, hWnd, uMsg, wParam, lParam
RET
.ENDIF

XOR eax, eax
RET
MainFrame_WndProc ENDP
end fractus
Posted on 2003-07-05 10:06:35 by cgurleyuk
You forgot the RET in InitInstance which makes it go again to RegisterWindowClasses and then crashes.
Posted on 2003-07-05 10:23:35 by JimmyClif


INVOKE ShowWindow, hWnd, dwCmdShow
INVOKE UpdateWindow, hWnd
InitInstance ENDP


should be
INVOKE ShowWindow, hWnd, dwCmdShow

INVOKE UpdateWindow, hWnd
ret
InitInstance ENDP
Posted on 2003-07-05 10:25:56 by roticv