FVBUSICOULOUR 15
Destruktor
Mittwoch, 02. April 2008 um 23:25
Prototype CallExitProc(param) 

Structure pbcallfunc
call.CallExitProc
prio.l
param.l
EndStructure

Global NewList CALLFUNCOBJ.pbcallfunc()

oldExitProtect = 0
*ExitOffset.long = 0

!MOV eax,_PB_EOP
!ADD eax,1
!MOV [p_ExitOffset],eax

Procedure cf_Destructor()
ForEach CALLFUNCOBJ()
CALLFUNCOBJ()\call(CALLFUNCOBJ()\param)
Next
!CALL _PB_EndFunctions
EndProcedure

Procedure Destructor(proc,prio=#PB_Ignore,param=0)
Static wprio.l = #PB_Ignore

If proc
If InsertElement(CALLFUNCOBJ())

CALLFUNCOBJ()\call = proc
CALLFUNCOBJ()\param = param

If prio = #PB_Ignore
CALLFUNCOBJ()\prio = wprio
wprio + 1
Else
CALLFUNCOBJ()\prio = prio
EndIf

SortStructuredList(CALLFUNCOBJ(),1,OffsetOf(pbcallfunc\prio),#PB_Sort_Long)
EndIf
EndIf
EndProcedure

VirtualProtect_(*ExitOffset,4,#PAGE_READWRITE,@oldExitProtect)
*ExitOffset\l = @cf_Destructor() - (*ExitOffset + 4)
VirtualProtect_(*ExitOffset,4,oldExitProtect,@oldExitProtect)
Beispiel :
Procedure exit1(param) 
PrintN("ende : 1 -> " +Str(param))
EndProcedure

Procedure exit2(param)
PrintN("ende : 2 -> " +Str(param))
EndProcedure

Procedure exit3(param)
PrintN("ende : 3 -> " +Str(param))
EndProcedure

Procedure exit4(param)
PrintN("ende : 4 -> " +Str(param))
EndProcedure

Destructor(@exit1())
Destructor(@exit2(),10)
Destructor(@exit3(),1,444)
Destructor(@exit4(),1)

OpenConsole()
PrintN("Ausgabe : ")
 
Kommentare (1)
1 Samstag, 17. Januar 2009 um 22:45
Thing
Die Idee hier Codes auszustellen ist ja ganz nett. Da der Code Stil aber zu wünschen übrig läßt ist das meiste aber unbrauchbar.
© 2012 www.realsource.de
free Joomla Template by funky-visions.de powered by greatnet.de Webhosting