The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Trope on March 25, 2005, 12:21:16 AM

Title: Why wont this INVOKE work?
Post by: Trope on March 25, 2005, 12:21:16 AM
This has to do with creating a dialog box as main.

This is NOT my code, I am just tearing through it to study it.

Ok, this is HIS code:



call GetModuleHandleA ; module base
mov hInst, eax ; save it

sub edx,edx

push edx ; lParam WM_INITDIALOG
push offset _dlgproc ; dialog proc
push edx ; parent handle
push IDD_DIALOG1 ; ID
push eax ; module base
call DialogBoxParamA

      jmp _normal_exit            ; Only here when dialog is closed



and I wanted to simplify it to this:



call GetModuleHandleA ; module base
mov hInst, eax ; save it

        invoke DialogBoxParamA,  NULL, addr _dlgproc, NULL, IDD_DIALOG1, hInst




and it don't work. Says invalid argument 2.

Any ideas why this is happening?

Title: Re: Why wont this INVOKE work?
Post by: hutch-- on March 25, 2005, 12:44:22 AM
Giovanni,

Try this from the MASM32 example code. Its in example2\resdlg2 .


    .code

start:

      invoke GetModuleHandle, NULL
      mov hInstance, eax
     
      ; -------------------------------------------
      ; Call the dialog box stored in resource file
      ; -------------------------------------------
      invoke DialogBoxParam,hInstance,ADDR dlgname,0,ADDR WndProc,0

      invoke ExitProcess,eax

Title: Re: Why wont this INVOKE work?
Post by: raymond on March 25, 2005, 02:45:39 AM
Trope

When you use the invoke, the parameters are pushed in the reverse order; i.e. the last parameter is pushed first, followed by the second-to-last, etc.., the first parameter being pushed last.

When you look at the description of an API in the Win32 Programmer's Reference, the parameters would be listed in the sequence they should appear following invoke. And the last parameter listed would be the first one pushed.

Raymond