Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ MarshalToBSTR()

unsafe IntPtr System.Security.SecureString.MarshalToBSTR ( )
inlinepackage

Definition at line 322 of file SecureString.cs.

323 {
324 lock (_methodLock)
325 {
328 SafeBuffer bufferToRelease = null;
329 IntPtr intPtr = IntPtr.Zero;
330 int length = 0;
331 try
332 {
333 Span<char> span = AcquireSpan(ref bufferToRelease);
335 intPtr = Marshal.AllocBSTR(length);
336 span.Slice(0, length).CopyTo(new Span<char>((void*)intPtr, length));
337 IntPtr result = intPtr;
338 intPtr = IntPtr.Zero;
339 return result;
340 }
341 finally
342 {
343 if (intPtr != IntPtr.Zero)
344 {
345 new Span<char>((void*)intPtr, length).Clear();
346 Marshal.FreeBSTR(intPtr);
347 }
349 bufferToRelease?.DangerousRelease();
350 }
351 }
352 }
static IntPtr AllocBSTR(int length)
Definition Marshal.cs:1730
static void FreeBSTR(IntPtr ptr)
Definition Marshal.cs:1750
unsafe Span< char > AcquireSpan(ref SafeBuffer bufferToRelease)

References System.Security.SecureString._decryptedLength, System.Security.SecureString._methodLock, System.Security.SecureString.AcquireSpan(), System.Runtime.InteropServices.Marshal.AllocBSTR(), System.Span< T >.Clear(), System.Runtime.InteropServices.SafeHandle.DangerousRelease(), System.Security.SecureString.EnsureNotDisposed(), System.Runtime.InteropServices.Marshal.FreeBSTR(), System.length, System.Security.SecureString.ProtectMemory(), System.Span< T >.Slice(), System.Security.SecureString.UnprotectMemory(), and System.IntPtr.Zero.