Categories
Development

Code Review FUN!

Legacy code can be fun!
How many wrongs make a right? The more the merrier?

//VB.NET
Public Function ConvertSDToStringSD(ByVal securityDescriptor() As Byte, ByVal securityInfo As Integer) As String

Dim pStringSD As IntPtr
Dim stringSDLen As Integer
Dim success As Boolean = ConvertSecurityDescriptorToStringSecurityDescriptor(securityDescriptor, 1, securityInfo, pStringSD, stringSDLen)
‘ The following ensures that the memory allocated to pStringSD by the unmanaged
‘ Win32 API is freed.
Try

If Not success Then

Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error)

End If
Return Marshal.PtrToStringAuto(pStringSD, stringSDLen)

Finally

If (pStringSD IntPtr.Zero) Then

Marshal.FreeHGlobal(pStringSD)

End If
pStringSD = IntPtr.Zero

End Try

End Function

TOM ANGRY, can you guess why?

1 reply on “Code Review FUN!”

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve this: Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.