Share your advanced PureBasic knowledge/code with the community.
wilbert
PureBasic Expert
Posts: 3943 Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands
Post
by wilbert » 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
dell_jockey
Enthusiast
Posts: 767 Joined: Sat Jan 24, 2004 6:56 pm
Post
by dell_jockey » Mon Oct 11, 2004 10:26 am
Wilbert,
Cool! Nice example of how to tap into what M$ already put onto our pc's !
'Bedankt' for sharing it!
blueznl
PureBasic Expert
Posts: 6166 Joined: Sat May 17, 2003 11:31 am
Contact:
Post
by blueznl » Wed Oct 13, 2004 8:01 am
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?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide
right here ... )
Fred
Administrator
Posts: 18253 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Wed Oct 13, 2004 10:29 am
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.