Hi Jason,
you can translate BSTR to FreeBasic String using this procedure. I make no assumptions about the internal descriptors of FB strings. The string may contain any characters including binary. I use assembler to copy the bytes fast and also avoid syntax complications in FB.
You will need to include the Windows API to handle Bstrings
FreeBasic Source
Function BSTR_to_FBstr( byval srcBSTR as BSTR) as string
dim as long i
dim as any ptr j
dim as string s
asm
mov eax,[srcBSTR]
mov ecx,[eax-4]
mov [i],ecx
end asm
if i>0 then
s=space$(i)
j=strptr(s)
asm
mov esi,[srcBSTR]
mov edi,[j]
mov ecx,[i] 'length of data
nexch:
mov al,[esi] ' src
mov [edi],al ' dest
inc esi
inc edi
dec ecx
jnz nexch
end asm
end if
function=s
end function
To return a BSTR from an FB string:
FreeBasic Source
Function FBString_to_BSTR(byref FBstring) as BSTR
dim as any ptr p
p=strptr(FBstring)
Function = SysAllocStringByteLen( p, len(FBstring) )
End Function
Bookmarks