need help with bstr
Posted: Sat Jan 05, 2008 8:24 pm
just for fun I am trying to import the decimal functions available in the oleaut32.dll, but bstr has me baffled, I Googled for hours but still don't know anymore than I did before, here's what I have so far.
note you will need to make your own import lib as the lib that comes with PB is missing the decimal arithmetic functions.
note you will need to make your own import lib as the lib that comes with PB is missing the decimal arithmetic functions.
Code: Select all
Structure decimal
wReserved.w
scale.b
sign.b
hi32.l
lo64.q
EndStructure
Structure DATE
date.d
EndStructure
Structure CY
int64.q
EndStructure
Procedure StringToBStr (string$) ; By Zapman Inspired by Fr34k
Protected Unicode$ = Space(Len(String$)* 2 + 2)
Protected bstr_string.l
PokeS(@Unicode$, String$, -1, #PB_Unicode)
bstr_string = SysAllocString_(@Unicode$)
ProcedureReturn bstr_string
EndProcedure
Procedure.s ReadBstr(*String.s) ; By Fr34k
Result$ = ""
If *String
length.l = WideCharToMultiByte_(#CP_ACP, 0, *String, -1, 0, 0, 0, 0)
*Buffer.l = AllocateMemory(length)
If *Buffer
WideCharToMultiByte_(#CP_ACP, 0, *String, -1, *Buffer, length, 0, 0)
Result$ = PeekS(*Buffer)
FreeMemory(*Buffer)
EndIf
EndIf
ProcedureReturn Result$
EndProcedure
Import "oleaut32.lib"
VarUI1FromDec.l ( *pdecIn.decimal, *pbOut.b ) As "_VarUI1FromDec@8"
VarI2FromDec.l ( *pdecIn.decimal, *psOut.w ) As "_VarI2FromDec@8"
VarI4FromDec.l ( *pdecIn.decimal, *plOut.l ) As "_VarI4FromDec@8"
VarR4FromDec.l ( *pdecIn.decimal, *pfltOut.f ) As "_VarR4FromDec@8"
VarR8FromDec.l ( *pdecIn.decimal, *pdblOut.d ) As "_VarR8FromDec@8"
VarDateFromDec.l ( *pdecIn.decimal, *pdateOut.DATE ) As "_VarDateFromDec@8"
VarCyFromDec.l ( *pdecIn.decimal, *pcyOut.q ) As "_VarCyFromDec@8"
VarBstrFromDec.l ( *pdecIn.decimal, lcid.l, dwFlags.l, *pbstrOut.s) As "_VarBstrFromDec@16"
VarBoolFromDec.l ( *pdecIn.decimal, *pboolOut.l ) As "_VarBoolFromDec@8"
VarI1FromDec.l ( *pdecIn.decimal, *pcOut.b ) As "_VarI1FromDec@8"
VarUI2FromDec.l ( *pdecIn.decimal, *puiOut.w ) As "_VarUI2FromDec@8"
VarUI4FromDec.l ( *pdecIn.decimal, *pulOut.l ) As "_VarUI4FromDec@8"
VarDecFromUI1.l ( bIn.b, *pdecOut.decimal ) As "_VarDecFromUI1@8"
VarDecFromI2.l ( uiIn.w, *pdecOut.decimal ) As "_VarDecFromI2@8"
VarDecFromI4.l ( lIn.l, *pdecOut.decimal ) As "_VarDecFromI4@8"
VarDecFromR4.l ( fltIn.f, *pdecOut.decimal ) As "_VarDecFromR4@8"
VarDecFromR8.l ( dblIn.d, *pdecOut.decimal ) As "_VarDecFromR8@12"
VarDecFromDate.l ( dateIn.d, *pdecOut.decimal ) As "_VarDecFromDate@12"
VarDecFromCy.l ( dcyIn.q, *pdecOut.decimal ) As "_VarDecFromCy@12"
VarDecFromStr.l ( *strIn.s, lcid.l, dwFlags.l, *pdecOut.decimal ) As "_VarDecFromStr@16"
;VarDecFromDisp.l ( *pdispIn.l, lcid.l, *pdecOut.decimal ) As "_VarDecFromDisp@12"
VarDecFromBool.l ( boolIn.l , *pdecOut.decimal ) As "_VarDecFromBool@8"
VarDecFromI1.l ( cIn.b , *pdecOut.decimal ) As "_VarDecFromI1@8"
VarDecFromUI2.l ( uiIn.w , *pdecOut.decimal ) As "_VarDecFromUI2@8"
VarDecFromUI4 ( ulIn.l , *pdecOut.decimal ) As "_VarDecFromUI4@8"
VarDecAdd.l ( *pdecLeft.decimal, *pdecRight.decimal, *pdecResult.decimal) As "_VarDecAdd@12"
VarDecSub.l ( *pdecLeft.decimal, *pdecRight.decimal, *pdecResult.decimal) As "_VarDecSub@12"
VarDecMul.l ( *pdecLeft.decimal, *pdecRight.decimal, *pdecResult.decimal) As "_VarDecMul@12"
VarDecDiv.l ( *pdecLeft.decimal, *pdecRight.decimal, *pdecResult.decimal) As "_VarDecDiv@12"
VarDecAbs.l ( *pdecIn.decimal, *pdecResult.decimal ) As "_VarDecAbs@8"
VarDecFix.l ( *pdecIn.decimal, *pdecResult.decimal ) As "_VarDecFix@8"
VarDecInt.l ( *pdecIn.decimal, *pdecResult.decimal ) As "_VarDecInt@8"
VarDecNeg.l ( *pdecIn.decimal, *pdecResult.decimal ) As "_VarDecNeg@8"
VarDecRound.l ( *pdecIn.decimal, cDecimals.l, *pdecResult.decimal ) As "_VarDecRound@12"
VarDecCmp.l ( *pdecLeft.decimal, *pdecRight.decimal ) As "_VarDecCmp@8"
VarDecCmpR8.l ( *pdecIn.decimal, dblRight.d ) As "_VarDecCmpR8@12"
EndImport
Define.decimal x,y,z
Define.w dw
cy.q
bstr.l=SysAllocStringLen_(bstr,255)
bstr2.l=StringToBStr ("3.1415926535897932384626433832795")
lcid.l
VarDecFromI4( 12345, x )
x\scale=3 ;x=12.345
VarDecAdd( x, x, y );y=24.690
VarI2FromDec( y, @dw )
VarDecFromStr( bstr2, lcid, 0, y)
VarBstrFromDec( y, lcid, 0, bstr )
Debug(dw)
Debug(ReadBstr(PeekL(bstr)))
SysFreeString_(bstr)
SysFreeString_(bstr2)