News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Prototyping external routines and invoke.

Started by bozo, October 04, 2005, 10:55:35 PM

Previous topic - Next topic

bozo

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?

hutch--

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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

QvasiModo

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?

bozo

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.

AeroASM

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?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

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.