copy method

BSTR copy()

Creates a deep copy of this BSTR.

The returned BSTR owns a newly allocated BSTR that must be released independently using SysFreeString.

This is equivalent to calling SysAllocString with the contents of this string.

Implementation

BSTR copy() {
  final bstr = SysAllocString(.new(this));
  if (bstr.isNull) throw StateError('Failed to allocate memory for BSTR.');
  return .new(bstr);
}