Struct ComBstrValue
- Namespace
- CsCom.Runtime
- Assembly
- CsCom.Runtime.dll
A BSTR stored in a field of a structure. It has the layout of the BSTR pointer, so it can be used in
blittable structures, and converts implicitly to string.
public readonly record struct ComBstrValue : IEquatable<ComBstrValue>
- Implements
- Inherited Members
Remarks
Like in C, the string is owned by the owner of the structure: a BSTR created by Allocate(string?)
must be released by Free() unless its ownership is transferred, e.g. to a COM method that frees it. The
default value is the null BSTR, which COM treats as an empty string.
Constructors
ComBstrValue(nint)
A BSTR stored in a field of a structure. It has the layout of the BSTR pointer, so it can be used in
blittable structures, and converts implicitly to string.
public ComBstrValue(nint Pointer)
Parameters
PointernintThe
BSTRpointer, or 0.
Remarks
Like in C, the string is owned by the owner of the structure: a BSTR created by Allocate(string?)
must be released by Free() unless its ownership is transferred, e.g. to a COM method that frees it. The
default value is the null BSTR, which COM treats as an empty string.
Properties
IsNull
Gets a value indicating whether the BSTR pointer is 0.
public bool IsNull { get; }
Property Value
Length
Gets the number of characters of the string.
public int Length { get; }
Property Value
Pointer
The BSTR pointer, or 0.
public nint Pointer { get; init; }
Property Value
Methods
Allocate(ReadOnlySpan<char>)
Allocates a BSTR with a copy of characters.
public static ComBstrValue Allocate(ReadOnlySpan<char> value)
Parameters
valueReadOnlySpan<char>
Returns
Allocate(string?)
Allocates a BSTR with a copy of a string.
public static ComBstrValue Allocate(string? value)
Parameters
valuestring
Returns
AsComBstr()
Gets a view of the BSTR that does not own it, or null if the pointer is 0.
public ComBstr? AsComBstr()
Returns
Free()
Releases the BSTR. The structure must not use it afterwards: assign default to the field.
public void Free()
ToString()
Copies the string; an empty string for the null BSTR.
public override string ToString()
Returns
Operators
implicit operator string?(ComBstrValue)
public static implicit operator string?(ComBstrValue value)
Parameters
valueComBstrValue