Page 1 of 1

Formatting string output

Posted: Sun Oct 10, 2004 1:22 pm
by wilbert

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

Posted: Mon Oct 11, 2004 10:26 am
by dell_jockey
Wilbert,

Cool! Nice example of how to tap into what M$ already put onto our pc's !
'Bedankt' for sharing it!

Posted: Wed Oct 13, 2004 8:01 am
by blueznl
interesting, but i don't understand all of it...

> pStringBase.l = 0
> ! pushd [PB_StringBase]
> ! popd [v_pStringBase]

v_pStringbase is probably asm for @pStringBase?

is that a purbasic system var or function, PB_StringBase?

Posted: Wed Oct 13, 2004 10:29 am
by Fred
Yes, v_pStringBase is the asm equivalent to pStringBase. About 'PB_StringBase, it's an internal variable (not available directly in PureBasic) which store the current pointer in the internal string manipulation buffer.