Formatting string output
Posted: Sun Oct 10, 2004 1:22 pm
Code: Select all
; retrieve the pointer to the stringbuffer
pStringBase.l = 0
! pushd [PB_StringBase]
! popd [v_pStringBase]
; get the handle of the MSVCRT library
hMSVCRT.l = GetModuleHandle_("msvcrt.dll")
; get the address of the function we need
fFormat.l = GetProcAddress_(hMSVCRT, "_snprintf")
; double float low / high functions
Procedure.l dfHigh(value.f)
! fld dword [esp]
! push eax
! push eax
! fstp qword [esp]
! add esp,4
! pop eax
ProcedureReturn
EndProcedure
Procedure.l dfLow(value.f)
! fld dword [esp]
! push eax
! push eax
! fstp qword [esp]
! pop eax
! add esp,4
ProcedureReturn
EndProcedure
; test the format function
floatValue.f = 22 / 7
CallFunctionFast(fFormat, pStringBase, 1024, "Hai %s, %i divided by %i equals %.2f", "PB user", 22, 7, dfLow(floatValue),dfHigh(floatValue))
myFormattedString.s = PeekS(pStringBase)
Debug myFormattedString