Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:56:07+00:00 2026-06-10T16:56:07+00:00

I have managed to create a window (thanks to everyone here at SO!), but

  • 0

I have managed to create a window (thanks to everyone here at SO!), but whenever it runs, the window forms, but it immediately breaks and a window pops up saying “test.exe has stopped responding” (test.exe being the name of the program).

Here is the code:

.386 
.model flat,stdcall 
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc 
include \masm32\include\user32.inc 
include \masm32\include\kernel32.inc 
include \masm32\include\gdi32.inc 
includelib \masm32\lib\user32.lib 
includelib \masm32\lib\kernel32.lib 
includelib \masm32\lib\gdi32.lib

 .data 
 ClassName db "SimpleWinClass",0 
 AppName  db "If you get this, it worked.",0 
 char WPARAM 20h                       

.data? 
hInstance HINSTANCE ? 
CommandLine LPSTR ?

.code 
start: 
push NULL
call GetModuleHandle 
mov    hInstance,eax 
call GetCommandLine
mov CommandLine,eax
push SW_SHOWDEFAULT
push CommandLine
push NULL
push hInstance
call WinMain
push eax
call ExitProcess

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD 
LOCAL wc:WNDCLASSEX 
LOCAL msg:MSG 
LOCAL hwnd:HWND 
mov   wc.cbSize,SIZEOF WNDCLASSEX 
mov   wc.style, CS_HREDRAW or CS_VREDRAW 
mov   wc.lpfnWndProc, OFFSET WndProc 
mov   wc.cbClsExtra,NULL 
mov   wc.cbWndExtra,NULL 
push  hInst 
pop   wc.hInstance 
mov   wc.hbrBackground,COLOR_WINDOW+1 
mov   wc.lpszMenuName,NULL 
mov   wc.lpszClassName,OFFSET ClassName 
push IDI_APPLICATION
push NULL
call LoadIcon
mov   wc.hIcon,eax 
mov   wc.hIconSm,eax 
push IDC_ARROW
push NULL
call LoadCursor
mov   wc.hCursor,eax 
lea eax, wc
push eax
call RegisterClassEx
push NULL
push hInst
push NULL
push NULL
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push CW_USEDEFAULT
push WS_OVERLAPPEDWINDOW
lea eax, AppName
push eax
lea eax, ClassName
push eax
push NULL
call CreateWindowEx
    mov   hwnd,eax 
push SW_SHOWNORMAL
push hwnd
call ShowWindow  
  push hwnd
  call UpdateWindow
     .WHILE TRUE 
         push 0
         push 0
         push NULL
         lea eax, msg
         push eax
         call GetMessage
         .BREAK .IF (!eax)
        lea eax, msg
        push eax
        call TranslateMessage
        lea eax, msg
        call DispatchMessage
     .ENDW 
     mov     eax,msg.wParam 
     ret 
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM 
    LOCAL hdc:HDC 
    LOCAL ps:PAINTSTRUCT

    .IF uMsg==WM_DESTROY 
    push NULL
    call PostQuitMessage
    .ELSEIF uMsg==WM_CHAR 
        push wParam 
        pop  char 
    push TRUE
    push NULL
    push hWnd
    call InvalidateRect
     .ELSEIF uMsg==WM_PAINT 
    lea eax, ps
    push eax
    push hWnd
    call BeginPaint
        mov    hdc,eax 
    push 1
    lea eax, char
    push eax
    push 0
    push 0
    push hdc
    call TextOut
    lea eax, ps
    push eax
    push hWnd
    call EndPaint
    .ELSE 
    push lParam
    push wParam
    push uMsg
    push hWnd
    call DefWindowProc
        ret 
    .ENDIF 
        xor    eax,eax 
        ret 
    push 0
    call ExitProcess
WndProc endp 
end start  

Why does it keep breaking? I’ve seen the same thing occur when I don’t put in call ExitProcess but I have this time, so why would it keep shutting down?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:56:08+00:00Added an answer on June 10, 2026 at 4:56 pm

    Since your a beginner and using MASM, I HIGHLY recommend you NOT using push/calls!!!! You gain NOTHING in not using INVOKE besides bugs.

    If you have used invoke, ml would of caught the problem.

    Are you missing something here?

    lea eax, msg
    call DispatchMessage
    

    Your forgetting to push eax!

    Also, for your sake and everyone else that has to read your code, please use an indentation style. Usually there is 4 spaces between the left margin and mnuemonics.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have managed to create a custom action in C# using MakeSfxCA which is
I have managed to create a simple app which deletes (bypassing the recycle bin)
I have created some documents and managed to make some simple queries but I
I have an app where I create a Window in WPF that the user
I'm doing a C# project window service. 1st time doing it. I have managed
My knowledge of regex is very weak. So far I have manage to create
I have a page which basically allows an admin user to create manager user
I have tried FBConnect for iPhone and am able to create/manage sessions and upload
I have the following StateManager: Lead.StateManager = Ember.StateManager.extend initialState: 'notParsing' notParsing: Ember.State.create startParsing: (manager,
I have an Application (an appointment manager) which lets the user create usercontrols in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.