Search code examples
windowsassemblyx86masm32

x86 assembly creating windows - errors A2111: conflicting parameter definition and A2008: syntax error - how to fix?


I'm following Iczelion's Win32 tutorials, specifically tutorial 3 ("A Simple Window"), and when trying to "strip out" some of the error handling and unnecessary code for the sake of experimentation, I get the following error when compiling:

test.asm(38) : error A2111: conflicting parameter definition.

Here is the line:

Line 38:

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdShow:DWORD

My question is: What is wrong with this line of code?

Thanks in advance.

EDIT:

Here is the entire script, with the offending line commented in:

.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 "Testwin", 0
    AppName db "Testing Window", 0

.data?

    hInstance HINSTANCE ?

.code 
start: 

    push NULL
    call GetModuleHandle
        mov  hInstance,eax
    push SW_SHOWDEFAULT
    push NULL
    push hInstance
    call WinMain
    push eax
        call ExitProcess

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdShow:DWORD   ; this is the line
; local vars:
LOCAL wc:WNDCLASSEX 
    LOCAL msg:MSG 
    LOCAL hwnd:HWND

; defining the window:
    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 
    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 
;create the window
    invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ 
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\ 
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\ 
           hInst,NULL
    invoke ShowWindow,hwnd,CmdShow
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM   
    cmp uMsg, WM_DESTROY
    jne _next
    invoke PostQuitMessage, NULL
_next:

WndProc endp      
end start    

Hope this helps.


Solution

  • The three error messages explain exactly what you did wrong.

    test.asm(38) : error A2111: conflicting parameter definition.
    

    Look at your prototype again:

    WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdShow:DWORD
    

    The parameters to WinMain conflict with a previous declaration. If you look at the earlier declaration, you'll see that the parameter lists are different.

    The next error:

    test.asm(69) : error A2008: syntax error: WndProc
    

    Let's look at that line:

    WndProc WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    

    Syntax error means that you violated the grammar. In this case, it's because the assembler couldn't figure out what to do with the second WndProc; repeating WndProc is not legal here.

    Third error:

    test.asm(75) : fatal error A1010: unmatched block nesting: WndProc
    

    Since the WndProc procedure never got properly started, your attempt to end it was invalid.

    TL;DR: Read the error messages. They will explain what you did wrong.