Recently I had to write an application using removable media and had to figure out an â€Ã...“EXISTSâ€Ã, function,
which checks existence of files without triggering the â€Ã...“unkillableâ€Ã, Ã¢â‚¬Ã...“can’t find drive..’retry’’abort’’continue’â€Ã,Â
message from Windows.
Now I extended this function with some goodies and thought put it here may some find it useful.
I also wrote a little tutorial and attached some macros for how to use MASM developing for Ebasic.
Csaba
Thanks!
Larry
Hi,
Thank you for sharing this.
Haim
Thanks for sharing.
You wellcome guys, :D
I forgot to write in my tutorial that the â€Ã...¾_invokeâ€Ã...“ replacement macro isn’t completed yet.
It doesn’t take care of â€Ã...“Câ€Ã, calls.
Because this intended to help write functions only for EB not for main programs usually you can omit
balancing the stack since â€Ã...“leaveâ€Ã, will restore the stack.
However you can get into trouble if you use â€Ã...“Câ€Ã, function(s) in loop(s).
So I fixed the macro for completeness.
I didn’t try it too much but I think it works.
Declarations:
=======================================================
.686p
.model flat
include Macros.inc
;Sample code does nothing
; ------------------------------------------------------------------
wsprintfA PROTO C :VARARG ;C declaration for SYSCALL
extrn __imp__snprintf:near ;C declaration as STDCALL
extrn LEFT$:near ;EBasic direct call
extrn __imp_RtlMoveMemory:near ;API STDCALL
; ===========================================================================
.code
; =============== S U B R O U T I N E =======================================
Pilot proc near syscall public uses esi X:DWORD
_invoke wsprintfA, eax,ebx,ecx,edx ;Stack will be ballanced (SYSCALL)
_invoke __imp__wsprintfA, eax,ebx,ecx,edx ;Stack will not be ballanced (STDCALL)
_invoke __imp_RtlMoveMemory, eax,ebx,ecx ;Stack ballanced by the called procedure
_invoke LEFT$, eax,ecx ;Stack ballanced by the called procedure
_invoke wsprintfA ;Stack don't need to be ballanced
ret 4
Pilot endp
end
====================================================================
Invoke replacement:
_invoke MACRO funcname:REQ,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20
LOCAL pos,counter,opat
counter=0
FOR arg,<p20,p19,p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>
IFNB <arg>
counter=counter+4
pos=@InStr(1,arg,<ADDR >) OR @InStr(1,arg,<addr >) OR @InStr(1,arg,<Addr >)
IF pos
opat = OPATTR(@SubStr(arg,%pos+5))
IF ((opat) EQ 98) OR ((opat) EQ 34) OR ((opat) EQ 42)
lea eax,@SubStr(<arg>,%pos+5)
push eax
ELSE
push OFFSET @SubStr(<arg>,%pos+5)
ENDIF
ELSE
push arg
ENDIF
ENDIF
ENDM
IF (@InStr(1,funcname,<__imp_>))
call dword ptr ds:funcname
ELSE
IF ((OPATTR(funcname)) AND 11100000000y) EQ 00100000000y ; Handle C functions
IF counter NE 0
@CatStr (<extrn __imp__>,funcname,<:near>)
@CatStr (<call dword ptr ds:>, <__imp__>,funcname)
add esp,counter
ELSE
@CatStr (<extrn __imp__>,funcname,<:near>)
@CatStr (<call dword ptr ds:>, <__imp__>,funcname)
ENDIF
ELSE
call funcname
ENDIF
ENDIF
ENDM