Author Topic: convert BSTR to FBSTRING  (Read 456 times)

0 Members and 1 Guest are viewing this topic.

Offline Peter Weis

  • Sr. Member
  • ****
  • Posts: 333
convert BSTR to FBSTRING
« on: May 05, 2018, 04:02:09 PM »
Basic is not always slower than assembler

Code: [Select]

FUNCTION BSTR_to_FBstr Alias "BSTR_to_FBstr" (ByVal srcBSTR AS BSTR)  AS String Export
  Dim AS LONG i
  Dim AS Byte 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
       
                 cld
                 Shr ecx, 1
                 rep movsw
                 jnb NotNext
                     movsb
                 NotNext:
             
          End ASM
  End If
 
  Function = s
End Function

This is much faster though written in basic and not with inline code

Code: [Select]

FUNCTION BSTR_to_FBstr2 Alias "BSTR_to_FBstr2" (Byval s AS bstr ptr)  AS String Export
Function = *Cast(zstring Ptr,s)
End Function