The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: rags on September 30, 2005, 06:34:25 AM

Title: TYPEDEF PROTO?
Post by: rags on September 30, 2005, 06:34:25 AM
Can someone explain what would be the purpose of TYPEDEF PROTO, why would it be used?
The masm manual doesn't give an example of its use.
thanks
rags
Title: Re: TYPEDEF PROTO?
Post by: James Ladd on September 30, 2005, 07:35:09 AM
A typedef proto would be used to define a pointer to a function so that when used
the correct argument validation is done.
Title: Re: TYPEDEF PROTO?
Post by: hutch-- on September 30, 2005, 10:46:54 AM
rags,

See if this pair of macros has the TYPDEF data you are after.


    ; --------------------------------------------
    ; the following two macros are for prototyping
    ; direct addresses with a known argument list.
    ; --------------------------------------------
      SPROTO MACRO func_addr:REQ,arglist:VARARG     ;; STDCALL version
        LOCAL lp,var
        .data?
          func_addr dd ?
        .const
        var typedef PROTO STDCALL arglist
        lp TYPEDEF PTR var
        EXITM <equ <(TYPE lp) PTR func_addr>>
      ENDM

      CPROTO MACRO func_addr:REQ,arglist:VARARG     ;; C calling version
        LOCAL lp,var
        .data?
          func_addr dd ?
        .const
        var typedef PROTO C arglist
        lp TYPEDEF PTR var
        EXITM <equ <(TYPE lp) PTR func_addr>>
      ENDM
Title: Re: TYPEDEF PROTO?
Post by: ToutEnMasm on September 30, 2005, 12:32:23 PM
Hello,
At what he can be used ?
Here is a sample for dynamic call of dll function

;declare
   PExitProcess TYPEDEF PROTO :DWORD
   FExitProcess TYPEDEF PTR PExitProcess
   ExitProcess TEXTEQU <FExitProcess ptr AExitProcess>
;data

                AExitProcess dd 0
;code
               ;-- we have got HdllKernel by loadlibrary
   invoke GetProcAddress,HdllKernel,SADR("ExitProcess")
   mov AExitProcess,eax                           
               ;and now we can call the function in the same manners if there is
               ;the user32.inc and user32.lib included,but there are not loaded
               invoke ExitProcess,0
;---------------------------------------------------------------------------------------------------------------------------------------

It can be used also for com in the same manners

                       ToutEnMasm






Title: Re: TYPEDEF PROTO?
Post by: rags on September 30, 2005, 02:02:03 PM
Thank you for the explanations and examples of  how TYPEDEF PROTO is used.
Looking at the help file included with the masm32 package I was unable to make heads
or tails of it.
Thanks,
      Rags