Announcement

Collapse
No announcement yet.

FASTPROC and CALL DWORD

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • FASTPROC and CALL DWORD

    Is there an equivalent to CALL DWORD which can be used with FASTPROCs?

  • #2
    ?

    Had a problem with it?

    In Restrictions in Help for FASTPROC, CALL DWORD is not mentioned. And in Help for CALL DWORD, FASTPROC is listed in See Also at the bottom.

    That "implies" to me it should work. Failing source code? At least better description of problem?

    Cheers,
    Dale

    Comment


    • #3
      FASTPROC in DLL (called from main module) won't work because of no IMPORT or EXPORT allowed?

      ((a FASTPROC in a DLL can be called from within DLL.))
      Dale

      Comment


      • #4
        If you really know what you are doing, you can write a DLL that returns the address(s) of FASTPROC procedures from a single exported procedure, store the as DWORD addresses and use CALL DWORD if you can suffer it OR standard PUSH / CALL notation to call the addresses from the executable that does the call.
        hutch at movsd dot com
        The MASM Forum

        www.masm32.com

        Comment


        • #5
          Here is how to directly call a FASTPROC in a DLL from the calling EXE.

          The DLL.
          Code:
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
              #COMPILE DLL
          
              GLOBAL DLLinstance as DWORD     ' the DLLs instance handle
          
            ' -----------------------------------
            ' set correct paths for include files
            ' -----------------------------------
              #INCLUDE "\basic\include\win32api.inc"
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
          FUNCTION LibMain(BYVAL hInst    as LONG, _
                           BYVAL Reason   as LONG, _
                           BYVAL Reserved as LONG) as LONG
          
              Select Case Reason
                Case %DLL_PROCESS_ATTACH
                  DLLinstance = hInst         ' make DLL instance global
              End Select
          
              FUNCTION = 1                    ' needed so DLL will start
          
          END FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
          FUNCTION GetPointers ALIAS "GetPointers"(pArray() as DWORD) EXPORT as DWORD
          
              LOCAL pmcopy as DWORD
          
              pmcopy    = CodePtr(mcopy)      ' get the fastproc address
              pArray(0) = pmcopy              ' you can add as many as you like to the array
          
              FUNCTION = 0
          
          END FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
           FASTPROC mcopy
          
              PREFIX "!"
          
              push esi
              push edi
          
              mov esi, [esp+4][8]             ; source address
              mov edi, [esp+8][8]             ; destination address
              mov ecx, [esp+12][8]            ; byte count
              rep movsb
          
              pop edi
              pop esi
          
              ret 12    ; <<< error fixed here, did not balance the stack on exit.
          
              END PREFIX
          
           END FASTPROC
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          The calling EXE
          Code:
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
              #compile exe "calldll.exe"
          
              #include "\basic\include\win32api.inc"
          
              MACRO copymem(proc,src,dst,lnth)
                ! push lnth
                ! push dst
                ! push src
                ! call proc
              END MACRO
          
              MACRO ExportCall(proc,arr)
                ! push arr                                  ' pass the array address
                ! call proc                                 ' manually call the EXPORT
              END MACRO
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          
          FUNCTION PBmain as LONG
          
              #REGISTER NONE
          
              LOCAL dlltest as DWORD
              LOCAL GetPointers as DWORD
              LOCAL parr  as DWORD
              LOCAL psrc  as DWORD
              LOCAL pdst  as DWORD
              LOCAL lenst as DWORD
              LOCAL mcopy as DWORD
          
              DIM arr(16) as DWORD
          
            ' ---------------------------
            ' get the EXPORT from the DLL
            ' ---------------------------
              dlltest = LoadLibrary("dlltest.dll")
              GetPointers = GetProcAddress(dlltest,"GetPointers")
          
              parr = VarPtr(arr())                        ' get array address  
              ExportCall(GetPointers,parr)                ' MACRO to call EXPORT "GetPointers"
              mcopy = arr(0)                              ' get the mcopy address from array
          
            ' --------------------------------------
          
              a$ = "If you can see me, it worked OK"      ' source string
              b$ = "                               "      ' destination string
          
              psrc  = StrPtr(a$)                          ' source address
              pdst  = StrPtr(b$)                          ' destination address
              lenst = len(a$)                             ' get the string length
          
              copymem(mcopy,psrc,pdst,lenst)              ' MACRO to call DLL "mcopy"
          
              MsgBox b$,0,"FASTPROC from DLL"             ' display the destination string
          
          End FUNCTION
          
          ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
          Attached Files
          Last edited by Steve Hutchesson; 5 Sep 2018, 11:55 PM.
          hutch at movsd dot com
          The MASM Forum

          www.masm32.com

          Comment


          • #6
            Originally posted by Steve Hutchesson View Post
            Here is how to directly call a FASTPROC in a DLL from the calling EXE.
            Zounds! that is a generous gift, Steve.

            Sorry if my question seemed ambiguous Dale! Maybe I should have asked "how to call a FASTPROC in assembler".

            I think it goes something like this:

            Code:
            #compile exe
            #dim all
            #debug display
            
            fastproc myfastproc ( byval a as long) as long
                ? "fast" + str$(a)
            end fastproc = 77
            ''
            function pbmain () as long
                local lproc, lresult as long
            
                lproc = codeptr(myfastproc)
                ' push second parameter
                ! push 99
                ' push first parameter
                ! push 88
                ' like CALL DWORD!
                ! call lproc
                ' omit next instruction if the result is not required (or specified)
                ! mov lresult, eax
                ? str$(lresult)
                ? "done"
            
            end function
            Does that look right?

            Comment


            • #7
              Chris,

              In the example I posted above is the method of calling a FASTPROC in assembler. Note though that it is a bare FASTPROC that does not use the 2 arguments version.
              Code:
                  MACRO copymem(proc,src,dst,lnth)
                    ! push lnth
                    ! push dst
                    ! push src
                    ! call proc
                  END MACRO
              Its normal STDCALL where the arguments are pushed in reverse order and you call the FASTPROC with the "call" mnemonic.
              hutch at movsd dot com
              The MASM Forum

              www.masm32.com

              Comment

              Working...
              X