Marshal.PtrToStringBSTR(IntPtr) Method  
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 -> stringstatic member PtrToStringBSTR : nativeint -> stringPublic Shared Function PtrToStringBSTR (ptr As IntPtr) As StringParameters
- 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
ptr equals Zero.
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.