Marshal.SecureStringToBSTR(SecureString) 方法

定义

重要

此 API 不符合 CLS。

分配非托管二进制字符串 (BSTR)并将托管 SecureString 对象的内容复制到其中。Allocates an unmanaged binary string (BSTR) and copies the contents of a managed SecureString object into it.

public:
 static IntPtr SecureStringToBSTR(System::Security::SecureString ^ s);
public static IntPtr SecureStringToBSTR (System.Security.SecureString s);
[System.CLSCompliant(false)]
public static IntPtr SecureStringToBSTR (System.Security.SecureString s);
[System.Security.SecurityCritical]
public static IntPtr SecureStringToBSTR (System.Security.SecureString s);
static member SecureStringToBSTR : System.Security.SecureString -> nativeint
[<System.CLSCompliant(false)>]
static member SecureStringToBSTR : System.Security.SecureString -> nativeint
[<System.Security.SecurityCritical>]
static member SecureStringToBSTR : System.Security.SecureString -> nativeint
Public Shared Function SecureStringToBSTR (s As SecureString) As IntPtr

参数

s
SecureString

要复制的托管对象。The managed object to copy.

返回

IntPtr

非托管内存中将 s 参数复制到的地址;如果提供了 null 对象,则为 0。The address, in unmanaged memory, where the s parameter was copied to, or 0 if a null object was supplied.

属性

例外

s 参数为 nullThe s parameter is null.

没有足够的可用内存。There is insufficient memory available.

注解

SecureStringToBSTR 方法对于自定义封送或混合托管和非托管代码很有用。The SecureStringToBSTR method is useful for custom marshaling or when mixing managed and unmanaged code. 由于此方法会分配字符串所需的非托管内存,因此, BSTR 在通过调用方法完成后,始终释放 ZeroFreeBSTRBecause this method allocates the unmanaged memory required for a string, always free the BSTR when finished by calling the ZeroFreeBSTR method.

适用于