EnableExplicit

XIncludeFile #IncludePath + "BinaryBuffer_WriteMemEx.pb"
XIncludeFile #IncludePath + "BinaryBuffer_Invalidate.pb"

Procedure.i BinaryBuffer_WriteStringLP(*hBinWrBuffer.BinaryBufferStruct, xString.s)
  Define.i xLong1

  xLong1 = Len(xString)
  If xLong1 > $7fff
    BinaryBuffer_Invalidate(*hBinWrBuffer)
    Else
    CompilerIf #PB_Compiler_Unicode
      xLong1 | $8000
      BinaryBuffer_WriteMemEx(*hBinWrBuffer, @xLong1, 2)
      BinaryBuffer_WriteMemEx(*hBinWrBuffer, @xString, (xLong1 & $7fff) << 1)
      CompilerElse
      BinaryBuffer_WriteMemEx(*hBinWrBuffer, @xLong1, 2)
      BinaryBuffer_WriteMemEx(*hBinWrBuffer, @xString, xLong1)
      CompilerEndIf
    EndIf
  EndProcedure

; IDE Options = PureBasic 5.21 LTS (Windows - x86)
; CursorPosition = 3
; Folding = -
; EnableUnicode
; EnableXP