Code: Select all
Function Jack( ByVal Jill As ZString*20 ) As Long
Print Jill
Return 1
End Function
Dim x As ZString*20 = "0123456"
Jack( x )
Sleep
Code: Select all
Function Jack( ByVal Jill As ZString*20 ) As Long
Print Jill
Return 1
End Function
Dim x As ZString*20 = "0123456"
Jack( x )
Sleep
Code: Select all
Function Jack( ByVal Jill As ZString ptr ) As Long
Print *Jill
Return 1
End Function
Dim x As ZString*20 = "0123456"
Jack( x )
Sleep
Code: Select all
Function Jack( ByRef Jill As ZString ) As Long
Print Jill
Return 1
End Function
Dim x As ZString*20 = "0123456"
Jack( x )
Sleep
Code: Select all
extern "Windows"
declare function LoadLibraryEx alias "LoadLibraryExA"(byval as zstring ptr, byval as any ptr,byval as long) as any ptr
end extern
var L=loadlibraryex("C:\Windows\System32\oleaut32.dll",0,0)
dim allocstring as function( as any ptr) as any ptr
allocstring=dylibsymbol(L,"SysAllocString")
dim freestring as sub(as any ptr)
freestring=dylibsymbol(L,"SysFreeString")
dim as string chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ":chars+=lcase(chars)
if L andalso allocstring andalso freestring then
dim as any ptr s=allocstring(strptr(chars))
print *cast(zstring ptr,s) 's is a BSTR ?
freestring(s)
else
print "Error somewhere!"
print L
print allocstring
print freestring
end if
print "press a key to end"
sleep
Code: Select all
#include once "win/wtypes.bi"
#include once "win/unknwn.bi"
#include once "win/oleauto.bi"
'
sub StringToBSTR( byref sb as BSTR, byref cnv_string As ZString )
Dim As integer length
length = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @cnv_string, -1, NULL, 0)
sb=SysAllocStringLen(sb,length)
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @cnv_string, -1, sb, length)
End sub
function BstrToString(Strng as bstr ptr) as string' By Fr34k
dim as string result
dim as integer length
dim as zstring ptr buffer
Result = ""
If Strng then
length = WideCharToMultiByte(CP_ACP, 0, *Strng, -1, NULL, 0, NULL, NULL)
Buffer = Allocate(length)
If Buffer then
WideCharToMultiByte(CP_ACP, 0, *Strng, -1, Buffer, length, NULL, NULL)
Result = *Buffer
deallocate(Buffer)
EndIf
EndIf
Return Result
End function
Code: Select all
dim as bstr st
StringToBStr (st,"3.14159265358979323846264338328")
Print BstrToString(@st)
SysFreeString(st) 'free the memory taken by st