Rediger

Del via


Marshal.PtrToStringBSTR(IntPtr) Method

Definition

Allocates a managed String and copies a binary string (BSTR) stored in unmanaged memory into it.

public:
 static System::String ^ PtrToStringBSTR(IntPtr ptr);
[System.Security.SecurityCritical]
public static string PtrToStringBSTR (IntPtr ptr);
public static string PtrToStringBSTR (IntPtr ptr);
[<System.Security.SecurityCritical>]
static member PtrToStringBSTR : nativeint -> string
static member PtrToStringBSTR : nativeint -> string
Public Shared Function PtrToStringBSTR (ptr As IntPtr) As String

Parameters

ptr
IntPtr

nativeint

The address of the first character of the unmanaged string.

Returns

A managed string that holds a copy of the unmanaged string.

Attributes

Exceptions

Remarks

Call this method only on strings that were allocated with the unmanaged SysAllocString and SysAllocStringLen functions.

PtrToStringBSTR is useful for custom marshaling or when mixing managed and unmanaged code. Because this method creates a copy of the unmanaged string's contents, you must free the original string as appropriate. This method provides the opposite functionality of the Marshal.StringToBSTR method.

Applies to

See also