Marshal.PtrToStringBSTR(IntPtr) Marshal.PtrToStringBSTR(IntPtr) Marshal.PtrToStringBSTR(IntPtr) 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);
static member PtrToStringBSTR : nativeint -> string
Public Shared Function PtrToStringBSTR (ptr As IntPtr) As String

Parameters

ptr
IntPtr IntPtr IntPtr IntPtr

The address of the first character of the unmanaged string.

Returns

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

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Applies to

See also