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 -> 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
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.
Applies to
See also
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: I hele 2024 udfaser vi GitHub-problemer som feedbackmekanisme for indhold og erstatter det med et nyt feedbacksystem. Du kan få flere oplysninger under:Indsend og få vist feedback om