Class BStrFFM


public final class BStrFFM extends WindowsForeignFunctions
FFM utilities for handling BSTR (Basic String) - the string type used in COM automation.

A BSTR is a pointer to a null-terminated Unicode string preceded by a 4-byte length prefix. The pointer points to the first character, not the length prefix.

  • Method Details

    • fromString

      public static MemorySegment fromString(Arena arena, String str)
      Allocates a new BSTR and copies the specified string into it.
      Parameters:
      arena - the arena for string conversion
      str - the string to convert
      Returns:
      the BSTR pointer, or NULL if allocation failed
    • free

      public static void free(MemorySegment bstr)
      Frees a BSTR allocated by SysAllocString.
      Parameters:
      bstr - the BSTR to free
    • length

      public static int length(MemorySegment bstr)
      Returns the length of a BSTR in characters (not bytes).
      Parameters:
      bstr - the BSTR
      Returns:
      the length in characters, or 0 if null
    • toString

      public static String toString(MemorySegment bstr, Arena arena)
      Converts a BSTR to a Java String.
      Parameters:
      bstr - the BSTR pointer
      arena - the arena for memory reinterpretation
      Returns:
      the Java string, or empty string if null