The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: bozo on October 04, 2005, 10:55:35 PM

Title: Prototyping external routines and invoke.
Post by: bozo on October 04, 2005, 10:55:35 PM
tried searching forum for similar question, but couldn't find it.

how do i declare an external routine while still using INVOKE syntax?

like if my_strlen routine is in my_procs.asm (assembled seperately)
and i want to call it using invoke from my_program.asm linking later with my_procs.obj
how is that done?
Title: Re: Prototyping external routines and invoke.
Post by: hutch-- on October 04, 2005, 11:01:01 PM
Kernel,

Try either of these two macros from the masm32 macro file.


    ; --------------------------------------------
    ; 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: Prototyping external routines and invoke.
Post by: QvasiModo on October 05, 2005, 12:04:15 AM
Couldn't you simply share the same .inc file for both .asm modules, with the same procedure definitions, and then link both .obj files together?
Title: Re: Prototyping external routines and invoke.
Post by: bozo on October 05, 2005, 12:15:09 AM
Hey guys, thanks for response, its working now.

QuoteCouldn't you simply share the same .inc file for both .asm modules, with the same procedure definitions, and then link both .obj files together?

this would be better, i agree, but the additional assembly code is by someone else, who requested
no modification at all if used and distributed..so, i link it seperately.

also, i was just interested incase i ever use some other external routines that are written in another language.
Title: Re: Prototyping external routines and invoke.
Post by: AeroASM on October 05, 2005, 06:00:27 PM
SPROTO and CPROTO are overkill. you can just put in an ordinary proto statement, nad not bother with the addresses.

benefit 1: quicker, smaller code.
benefit 2: no reliance on external macros.

BTW I am confused at how you got the address of an external function?
Title: Re: Prototyping external routines and invoke.
Post by: hutch-- on October 05, 2005, 10:31:28 PM
It depends where the external module is. If it resides in a DLL where you have no library for it or if its a member of a virtual table that is not exported, the two macros work fine in this context but if the external modules are either object modules or in a library, you only need normal prototypes as the linker resolves that name.
Title: Re: Prototyping external routines and invoke.
Post by: AeroASM on October 06, 2005, 01:05:07 PM
Quote from: Kernel_Gaddafi on October 04, 2005, 10:55:35 PM
like if my_strlen routine is in my_procs.asm (assembled seperately)
and i want to call it using invoke from my_program.asm linking later with my_procs.obj
how is that done?
Quote from: hutch-- on October 05, 2005, 10:31:28 PM
It depends where the external module is. If it resides in a DLL where you have no library for it or if its a member of a virtual table that is not exported, the two macros work fine in this context but if the external modules are either object modules or in a library, you only need normal prototypes as the linker resolves that name.

it doesn't reside in a DLL, he wants to link in the obj at link time.