flat assembler
Message board for the users of flat assembler.

Index > Windows > why doesnt this code work in windows 98?

Author
Thread Post new topic Reply to topic
thecf



Joined: 23 Dec 2006
Posts: 23
thecf
Hi

Could anyone help me out? I've been having problems with trying to get my window to appear on win98. it works fine in xp and vista but not on 98.

Code:
format PE gui
start:
  mov  eax,1
  cpuid
  test edx,800000h
  jz   no_mmx
  mov  [mmx],1
  no_mmx:
  push 0            ; lpModuleName
  call [GetModuleHandle]
  mov  [wc.hInstance],eax
  push 4            ; BLACK_BRUSH
  call [GetStockObject]
  mov  [wc.hbrBackground],eax
  push 32512            ; lpIconName (IDI_APPLICATION)
  push 0                ; hInstance
  call [LoadIcon]
  mov  [wc.hIcon],eax
  push 32512            ; lpCursorName (IDC_ARROW)
  push 0                ; hInstance
  call [LoadCursor]
  mov  [wc.hCursor],eax
  xor  eax,eax
  mov  [wc.style],eax
  mov  [wc.cbClsExtra],eax
  mov  [wc.cbWndExtra],eax
  mov  [wc.lpszMenuName],eax
  push wc               ; *lpWndClass
  call [RegisterClass]
  test eax,eax
  jz   error
  push 0            ; lpParam
  push [wc.hInstance] ; hInstance
  push 0            ; hMenu
  push 0            ; hWndParent
  push 400          ; nHeight
  push 400                ; nWidth
  push 20           ; y
  push 20           ; x
  push 0x16CF0000       ; dwStyle (WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU)
  push _title       ; lpWindowName
  push _classname   ; lpClassName
  push 0            ; dwExStyle
  call [CreateWindowEx]
  msg_loop:
  push 0                ; wMsgFilterMax
  push 0                ; wMsgFilterMin
  push 0                ; hWnd
  push msg              ; lpMsg
  call [GetMessage]
  test eax,eax
  jz   end_loop
  push msg               ; *lpMsg
  call [TranslateMessage]
  push msg           ; *lpMsg
  call [DispatchMessage]
  jmp  msg_loop
  error:
  push 0
  push 0
  push 0
  push 0
  call [MessageBox]
  end_loop:
  push [msg.wParam]  ; uExitCode
  call [ExitProcess]

window_proc:
  push ebp
  mov  ebp,esp
  push ebx
  push esi
  push edi
  hwnd equ dword[ebp+0x8]
  wmsg equ dword[ebp+0xC]
  wparam equ dword[ebp+0x10]
  lparam equ dword[ebp+0x14]
  cmp wmsg,0001h     ; WM_CREATE
  je wmcreate
  cmp wmsg,0002h      ; WM_DESTROY
  je wmdestroy
  cmp wmsg,000Fh   ; WM_PAINT
  je wmpaint

  defwndproc:
    push lparam
    push wparam
    push wmsg
    push hwnd
    call [DefWindowProc]
    jmp  finish

  wmpaint:
    push ps
    push hwnd
    call [BeginPaint]
    mov  al,[mmx]
    test al,al
    jz   nommx_code
    ; mmx code
    ;TextOut(hdc, 0, 0, "Hello, Windows!", 15);
    ;pxor mm0,mm0
    push hwnd
    call [GetDC]
    movd mm0,eax
    ;movd dword [mm0+0],'M'
    push 32
    push mmxsupport
    push 0
    push 0
    push eax
    call [TextOut]
    jmp  end_wmpaint
    nommx_code:

    end_wmpaint:
    push ps
    push hwnd
    call [EndPaint]
    xor  eax,eax
    jmp  finish

  wmcreate:
    xor  eax,eax
    jmp  finish

  wmdestroy:
    push 0  ; nExitCode
    call [PostQuitMessage]
    xor  eax,eax

  finish:
    pop ebx
    pop edi
    pop esi
    leave
    ret

  _title db 'win32',0
  _classname db 'win32test',0

  mmx db 0
  mmxsupport db 32 dup ('x')

  ; POINT
  pt:
  pt.x dd ?
  pt.y dd ?

  ; WNDCLASS
  wc:
  wc.style dd ?
  wc.lpfnWndProc dd window_proc
  wc.cbClsExtra dd ?
  wc.cbWndExtra dd ?
  wc.hInstance dd ?
  wc.hIcon dd ?
  wc.hCursor dd ?
  wc.hbrBackground dd ?
  wc.lpszMenuName dd ?
  wc.lpszClassName dd _classname

  ; MSG
  msg:
  msg.hwnd dd ?
  msg.message dd ?
  msg.wParam dd ?
  msg.lParam dd ?
  msg.time dd ?
  msg.pt dd pt

  ; RECT
  rect:
  rect.left dd ?
  rect.top dd ?
  rect.right dd ?
  rect.bottom dd ?
  
  ; PAINTSTRUCT
  ps:
  ps.hdc dd ?
  ps.fErase dd ?
  ps.rcPaint dd rect
  ps.fRestore dd ?
  ps.fIncUpdate dd ?
  ps.rgbReserved db 32 dup (?)

section '.idata' import data readable writeable

  dd 0,0,0,rva kernel_name,rva kernel_table
  dd 0,0,0,rva user32_name,rva user32_table
  dd 0,0,0,rva gdi32_name,rva gdi32_table
  dd 0,0,0,0,0
  
  kernel_table:
  ExitProcess dd rva _ExitProcess
  GetModuleHandle dd rva _GetModuleHandle
  dd 0
  
  user32_table:
  MessageBox dd rva _MessageBox
  LoadIcon dd rva _LoadIcon
  LoadCursor dd rva _LoadCursor
  RegisterClass dd rva _RegisterClass
  CreateWindowEx dd rva _CreateWindowEx
  GetMessage dd rva _GetMessage
  TranslateMessage dd rva _TranslateMessage
  DispatchMessage dd rva _DispatchMessage
  DefWindowProc dd rva _DefWindowProc
  PostQuitMessage dd rva _PostQuitMessage
  InvalidateRect dd rva _InvalidateRect
  GetDC dd rva _GetDC
  GetClientRect dd rva _GetClientRect
  ReleaseDC dd rva _ReleaseDC
  SetTimer dd rva _SetTimer
  PeekMessage dd rva _PeekMessage
  PostMessage dd rva _PostMessage
  LoadMenu dd rva _LoadMenu
  ShowWindow dd rva _ShowWindow
  UpdateWindow dd rva _UpdateWindow
  BeginPaint dd rva _BeginPaint
  EndPaint dd rva _EndPaint
  SendMessage dd rva _SendMessage
  dd 0
  
  gdi32_table:
  GetStockObject dd rva _GetStockObject
  TextOut dd rva _TextOut
  dd 0
  
  kernel_name db 'KERNEL32.DLL',0
  user32_name db 'USER32.DLL',0
  gdi32_name db 'GDI32.DLL',0
  
  _ExitProcess dw 0
  db 'ExitProcess',0
  _GetModuleHandle dw 0
  db 'GetModuleHandleA',0
  _MessageBox dw 0
  db 'MessageBoxA',0
  _LoadIcon dw 0
  db 'LoadIconA',0
  _LoadCursor dw 0
  db 'LoadCursorA',0
  _RegisterClass dw 0
  db 'RegisterClassA',0
  _CreateWindowEx dw 0
  db 'CreateWindowExA',0
  _GetMessage dw 0
  db 'GetMessageA',0
  _TranslateMessage dw 0
  db 'TranslateMessage',0
  _DispatchMessage dw 0
  db 'DispatchMessageA',0
  _DefWindowProc dw 0
  db 'DefWindowProcA',0
  _PostQuitMessage dw 0
  db 'PostQuitMessage',0
  _InvalidateRect dw 0
  db 'InvalidateRect',0
  _GetDC dw 0
  db 'GetDC',0
  _GetClientRect dw 0
  db 'GetClientRect',0
  _ReleaseDC dw 0
  db 'ReleaseDC',0
  _SetTimer dw 0
  db 'SetTimer',0
  _PeekMessage dw 0
  db 'PeekMessageA',0
  _PostMessage dw 0
  db 'PostMessageA',0
  _GetStockObject dw 0
  db 'GetStockObject',0
  _LoadMenu dw 0
  db 'LoadMenuA',0
  _ShowWindow dw 0
  db 'ShowWindow',0
  _UpdateWindow dw 0
  db 'UpdateWindow',0
  _BeginPaint dw 0
  db 'BeginPaint',0
  _EndPaint dw 0
  db 'EndPaint',0
  _TextOut dw 0
  db 'TextOutA',0
  _SendMessage dw 0
  db 'SendMessageA',0    
Post 29 Dec 2006, 19:19
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
very ugly code, which hard to read, why you coding in such style?
Post 30 Dec 2006, 09:36
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
try to change

finish:
pop ebx
pop edi
pop esi
leave
ret

to

finish:
pop edi
pop esi
pop ebx
leave
ret

figure out by yourself, why it should be so....
Post 30 Dec 2006, 10:09
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
yes, and in this code 'ret' must be 'retn 16'
Post 30 Dec 2006, 16:51
View user's profile Send private message Reply with quote
thecf



Joined: 23 Dec 2006
Posts: 23
thecf
Vasilev Vjacheslav wrote:
very ugly code, which hard to read, why you coding in such style?

What's wrong with the style? It's difficult to read but im just following the DIB.asm opengl example i found on this forum...
Post 30 Dec 2006, 17:07
View user's profile Send private message Reply with quote
thecf



Joined: 23 Dec 2006
Posts: 23
thecf
I tried changing the code you suggested but no look. The window does not appear on win98 though the app is running when you press ctrl+alt+del. Also when i push [wc.hInstance] with the square brackets it cause the 98 system to lock up. so i removed the brackets as well.

Code:
format PE gui
start:
  mov  eax,1 
  cpuid 
  test edx,800000h 
  jz   no_mmx 
  mov  [mmx],1 
  no_mmx: 
  push 0            ; lpModuleName 
  call [GetModuleHandle] 
  mov  [wc.hInstance],eax 
  push 4            ; BLACK_BRUSH 
  call [GetStockObject] 
  mov  [wc.hbrBackground],eax 
  push 32512            ; lpIconName (IDI_APPLICATION) 
  push 0                ; hInstance 
  call [LoadIcon] 
  mov  [wc.hIcon],eax 
  push 32512            ; lpCursorName (IDC_ARROW) 
  push 0                ; hInstance 
  call [LoadCursor] 
  mov  [wc.hCursor],eax 
  xor  eax,eax 
  mov  [wc.style],eax 
  mov  [wc.cbClsExtra],eax 
  mov  [wc.cbWndExtra],eax 
  mov  [wc.lpszMenuName],eax 
  push wc               ; *lpWndClass 
  call [RegisterClass] 
  test eax,eax 
  jz   error 
  push 0            ; lpParam 
  push wc.hInstance ; hInstance 
  push 0            ; hMenu 
  push 0            ; hWndParent 
  push 400          ; nHeight 
  push 400                ; nWidth 
  push 20           ; y 
  push 20           ; x 
  push 0x16CF0000       ; dwStyle (WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU) 
  push _title       ; lpWindowName 
  push _classname   ; lpClassName 
  push 0            ; dwExStyle 
  call [CreateWindowEx] 
  msg_loop: 
  push 0                ; wMsgFilterMax 
  push 0                ; wMsgFilterMin 
  push 0                ; hWnd 
  push msg              ; lpMsg 
  call [GetMessage] 
  test eax,eax 
  jz   end_loop 
  push msg               ; *lpMsg 
  call [TranslateMessage] 
  push msg           ; *lpMsg 
  call [DispatchMessage] 
  jmp  msg_loop 
  error: 
  push 0 
  push 0 
  push 0 
  push 0 
  call [MessageBox] 
  end_loop: 
  push [msg.wParam]  ; uExitCode 
  call [ExitProcess] 

window_proc:
  push ebp
  mov  ebp,esp
  push ebx
  push esi
  push edi
  hwnd equ dword[ebp+0x8]
  wmsg equ dword[ebp+0xC]
  wparam equ dword[ebp+0x10]
  lparam equ dword[ebp+0x14]
  cmp wmsg,0001h     ; WM_CREATE
  je wmcreate
  cmp wmsg,0002h      ; WM_DESTROY
  je wmdestroy
  cmp wmsg,000Fh   ; WM_PAINT
  je wmpaint

  defwndproc:
    push lparam
    push wparam
    push wmsg
    push hwnd
    call [DefWindowProc]
    jmp  finish

  wmpaint:
    push ps
    push hwnd
    call [BeginPaint]
    mov  al,[mmx]
    test al,al
    jz   nommx_code
    ; mmx code
    ;TextOut(hdc, 0, 0, "Hello, Windows!", 15);
    ;pxor mm0,mm0
    push hwnd
    call [GetDC]
    movd mm0,eax
    ;movd dword [mm0+0],'M'
    push 32
    push mmxsupport
    push 0
    push 0
    push eax
    call [TextOut]
    jmp  end_wmpaint
    nommx_code:

    end_wmpaint:
    push ps
    push hwnd
    call [EndPaint]
    xor  eax,eax
    jmp  finish

  wmcreate:
    xor  eax,eax
    jmp  finish

  wmdestroy:
    push 0  ; nExitCode
    call [PostQuitMessage]
    xor  eax,eax

  finish:
    pop  edi
    pop  esi
    pop  ebx
    leave
    retn 16

section '.data' data readable writeable

  _title db 'win32',0
  _classname db 'win32test',0

  mmx db 0
  mmxsupport db 32 dup ('x')

  ; POINT
  pt:
  pt.x dd ?
  pt.y dd ?

  ; WNDCLASS
  wc:
  wc.style dd ?
  wc.lpfnWndProc dd window_proc
  wc.cbClsExtra dd ?
  wc.cbWndExtra dd ?
  wc.hInstance dd ?
  wc.hIcon dd ?
  wc.hCursor dd ?
  wc.hbrBackground dd ?
  wc.lpszMenuName dd ?
  wc.lpszClassName dd _classname

  ; MSG
  msg:
  msg.hwnd dd ?
  msg.message dd ?
  msg.wParam dd ?
  msg.lParam dd ?
  msg.time dd ?
  msg.pt dd pt

  ; RECT
  rect:
  rect.left dd ?
  rect.top dd ?
  rect.right dd ?
  rect.bottom dd ?

  ; PAINTSTRUCT
  ps:
  ps.hdc dd ?
  ps.fErase dd ?
  ps.rcPaint dd rect
  ps.fRestore dd ?
  ps.fIncUpdate dd ?
  ps.rgbReserved db 32 dup (?)

section '.idata' import data readable writeable

  dd 0,0,0,rva kernel_name,rva kernel_table
  dd 0,0,0,rva user32_name,rva user32_table
  dd 0,0,0,rva gdi32_name,rva gdi32_table
  dd 0,0,0,0,0

  kernel_table:
  ExitProcess dd rva _ExitProcess
  GetModuleHandle dd rva _GetModuleHandle
  dd 0

  user32_table:
  MessageBox dd rva _MessageBox
  LoadIcon dd rva _LoadIcon
  LoadCursor dd rva _LoadCursor
  RegisterClass dd rva _RegisterClass
  CreateWindowEx dd rva _CreateWindowEx
  GetMessage dd rva _GetMessage
  TranslateMessage dd rva _TranslateMessage
  DispatchMessage dd rva _DispatchMessage
  DefWindowProc dd rva _DefWindowProc
  PostQuitMessage dd rva _PostQuitMessage
  InvalidateRect dd rva _InvalidateRect
  GetDC dd rva _GetDC
  GetClientRect dd rva _GetClientRect
  ReleaseDC dd rva _ReleaseDC
  SetTimer dd rva _SetTimer
  PeekMessage dd rva _PeekMessage
  PostMessage dd rva _PostMessage
  LoadMenu dd rva _LoadMenu
  ShowWindow dd rva _ShowWindow
  UpdateWindow dd rva _UpdateWindow
  BeginPaint dd rva _BeginPaint
  EndPaint dd rva _EndPaint
  SendMessage dd rva _SendMessage
  dd 0

  gdi32_table:
  GetStockObject dd rva _GetStockObject
  TextOut dd rva _TextOut
  dd 0

  kernel_name db 'KERNEL32.DLL',0
  user32_name db 'USER32.DLL',0
  gdi32_name db 'GDI32.DLL',0

  _ExitProcess dw 0
  db 'ExitProcess',0
  _GetModuleHandle dw 0
  db 'GetModuleHandleA',0
  _MessageBox dw 0
  db 'MessageBoxA',0
  _LoadIcon dw 0
  db 'LoadIconA',0
  _LoadCursor dw 0
  db 'LoadCursorA',0
  _RegisterClass dw 0
  db 'RegisterClassA',0
  _CreateWindowEx dw 0
  db 'CreateWindowExA',0
  _GetMessage dw 0
  db 'GetMessageA',0
  _TranslateMessage dw 0
  db 'TranslateMessage',0
  _DispatchMessage dw 0
  db 'DispatchMessageA',0
  _DefWindowProc dw 0
  db 'DefWindowProcA',0
  _PostQuitMessage dw 0
  db 'PostQuitMessage',0
  _InvalidateRect dw 0
  db 'InvalidateRect',0
  _GetDC dw 0
  db 'GetDC',0
  _GetClientRect dw 0
  db 'GetClientRect',0
  _ReleaseDC dw 0
  db 'ReleaseDC',0
  _SetTimer dw 0
  db 'SetTimer',0
  _PeekMessage dw 0
  db 'PeekMessageA',0
  _PostMessage dw 0
  db 'PostMessageA',0
  _GetStockObject dw 0
  db 'GetStockObject',0
  _LoadMenu dw 0
  db 'LoadMenuA',0
  _ShowWindow dw 0
  db 'ShowWindow',0
  _UpdateWindow dw 0
  db 'UpdateWindow',0
  _BeginPaint dw 0
  db 'BeginPaint',0
  _EndPaint dw 0
  db 'EndPaint',0
  _TextOut dw 0
  db 'TextOutA',0
  _SendMessage dw 0
  db 'SendMessageA',0
    
Post 30 Dec 2006, 19:08
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Confirming bugs:

- Original code at least 4 bugs, runs always into a hard freezer

- Fixed code still at least 3 bugs, does nothing. Bugs: CPUID without
availability test, "nommx" code lacks, ??? (does nothing even if MMX present).

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 30 Dec 2006, 23:04
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
Just a shot in the dark without really examining the code -- Windows 9x may have stricter import rules, use the import macro(s).

_________________
redghost.ca
Post 31 Dec 2006, 12:37
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
RedGhost is right, the import names must be sorted alphabetically
Post 31 Dec 2006, 15:32
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.