Table of Contents

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

Pointer nint

The BSTR pointer, 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

bool

Length

Gets the number of characters of the string.

public int Length { get; }

Property Value

int

Pointer

The BSTR pointer, or 0.

public nint Pointer { get; init; }

Property Value

nint

Methods

Allocate(ReadOnlySpan<char>)

Allocates a BSTR with a copy of characters.

public static ComBstrValue Allocate(ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>

Returns

ComBstrValue

Allocate(string?)

Allocates a BSTR with a copy of a string.

public static ComBstrValue Allocate(string? value)

Parameters

value string

Returns

ComBstrValue

The BSTR, or the null BSTR for null.

AsComBstr()

Gets a view of the BSTR that does not own it, or null if the pointer is 0.

public ComBstr? AsComBstr()

Returns

ComBstr

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

string

Operators

implicit operator string?(ComBstrValue)

Copies the string of a BSTR; null for the null BSTR.

public static implicit operator string?(ComBstrValue value)

Parameters

value ComBstrValue

Returns

string