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 8162539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:45:08+00:00 2026-06-06T18:45:08+00:00

I try to create the simplest WinAPI window using assembly NASM. I have problem

  • 0

I try to create the simplest WinAPI window using assembly NASM.
I have problem with Window Proc. Look at commented lines:

%macro API 2
    import %1 %2
    extern %1
%endmacro 

API GetModuleHandleA, kernel32.dll
API LoadIconA,user32.dll
API LoadCursorA,user32.dll
API RegisterClassExA, user32.dll
API CreateWindowExA, user32.dll
API MessageBoxA, user32.dll
API SendMessageA, user32.dll
API DefWindowProcA, user32.dll
API ExitProcess, kernel32.dll
API GetMessageA, user32.dll
API DispatchMessageA, user32.dll
API TranslateMessage,user32.dll
API ShowWindow,user32.dll
API UpdateWindow,user32.dll
API GetCommandLineA,kernel32.dll
API PostQuitMessage,user32.dll

segment .data USE32
    windowName db "Hello world!", 0
    cmdLine    dd 0
    hWnd       dd 0
    hInst      dd 0
    hCursor    dd 0
    className  db "moje_okno",0

    blad       db "Blad!!!",0

segment .bss
    struc WNDCLASSEX
        .sSize         resb 4
        .style         resb 4
        .wndProc       resb 4
        .clsExtra      resb 4
        .wndExtra      resb 4
        .hInstance     resb 4
        .hIcon         resb 4
        .hCursor       resb 4
        .background    resb 4
        .sMenuName     resb 4
        .sClassName    resb 4
        .hIconSm       resb 4
    endstruc 

    wndClass istruc WNDCLASSEX
    iend

global ..start
segment .text USE32
..start:
    push 0
    call [GetModuleHandleA]
    mov dword [hInst], eax ; application handle

    push dword 0x00007f00 ; MAKEINTRESOURCE(32512)
    push dword 0
    call [LoadCursorA]
    mov dword [hCursor], eax ; cursor handle

    mov dword [wndClass + WNDCLASSEX.sSize],      dword 48 ; struct size
    mov dword [wndClass + WNDCLASSEX.style],      dword 0 ; style
    mov dword [wndClass + WNDCLASSEX.wndProc],    wndproc ; window proc
    mov dword [wndClass + WNDCLASSEX.clsExtra],   dword 0 
    mov dword [wndClass + WNDCLASSEX.wndExtra],   dword 0
    mov eax, dword [hInst]
    mov dword [wndClass + WNDCLASSEX.hInstance],  eax ; handle
    mov dword [wndClass + WNDCLASSEX.hIcon],      dword 0
    mov eax, dword [hCursor]
    mov dword [wndClass + WNDCLASSEX.hCursor],    eax
    mov dword [wndClass + WNDCLASSEX.background], dword 0
    mov dword [wndClass + WNDCLASSEX.sMenuName],  dword 0
    mov dword [wndClass + WNDCLASSEX.sClassName], className ; class name
    mov dword [wndClass + WNDCLASSEX.hIconSm],    dword 0

    push wndClass
    call [RegisterClassExA] 
    call near sprawdz_blad ; check return value of RegisterClassExA

    push 0 ; param
    push dword [hInst] ; handle
    push 0 ;hMenu
    push 0 ;parent
    push 200 ;height
    push 200 ;width
    push 200 ;y
    push 200 ;x
    push 0 ;style
    push className ;window name
    push className ;window class
    push 0 ;extended style
    call [CreateWindowExA]
    push eax
    call near sprawdz_blad ;check return value of CreateWindowExA. RETURNS 0

    push 0
    call [ExitProcess]

wndproc:
    ; HERE I NEED ACCESS TO WINDOW PROC PARAMETERS: HWND, MSG, WPARAM, LPARAM
    ; I TRIED:
     pop eax
     pop ebx
     pop ecx
     pop edx
    ; BUT IT DOESN'T WORK
    ; THERE ARE NOT RIGHT VALUES IN THESE REGISTRIES 


    ret

box:
    push 0
    push blad
    push blad
    push 0
    call [MessageBoxA]
    ret

sprawdz_blad:
    pop eax
    cmp eax, 0
    jne ok ; if function returns 0 everything is allright

    push 0
    push blad
    push blad
    push 0
    call [MessageBoxA]

    push 1
    call [ExitProcess]
ok:
    ret


I try to make it work for hours but I’m out of ideas.
Please help.
Greetings, Michal.

  • 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-06T18:45:09+00:00Added an answer on June 6, 2026 at 6:45 pm

    A called subroutine, wheether you call it yourself or it’s called by Windows (like wndproc) has its return address as the first thing on the stack. You do NOT want to pop this! To access the parameters, you need to look farther up the stack. Try something like…

    wndproc:
        mov eax, [esp + 4]
        mov ebx, [esp + 8]
     ; etc...
    

    See if that helps…

    Best,
    Frank

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

Sidebar

Related Questions

I try to create the simplest Simplest WebServer and Client using HTTP. (Please, don't
For TDD you have to Create a test that fail Do the simplest thing
At the moment I have this: try{ // Create file FileWriter fstream = new
I try to do simplest listView. I create layout: <TextView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/history_menu_item android:layout_width=wrap_content android:layout_height=match_parent
I try create custom format for maven assembly plugin. I use following instruction how
I have recently set up Yii and when I try create an app via
I try create delegate type using an Expression class, but when I try create
I have the following code: try { //Create connection SQLiteConnection conn = DBConnection.OpenDB(); //Verify
I try to create simplest include tag with inclusion_tag. \main \templatetags \tegs_test.py \__init__.py Python
I try create a map for open ~/.vimrc, but open the ~/.vimrc only when

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.