internal static int ConvertSdToSddl(
byte[] binaryForm,
int requestedRevision,
SecurityInfos si,
out string resultSddl)
{
int errorCode;
IntPtr ByteArray;
uint ByteArraySize = 0;
if (!Interop.Advapi32.ConvertSdToStringSd(binaryForm, (uint)requestedRevision, (uint)si, out ByteArray, ref ByteArraySize))
{
errorCode = Marshal.GetLastWin32Error();
goto Error;
}
//
// Extract data from the returned pointer
//
resultSddl = Marshal.PtrToStringUni(ByteArray);
//
// Now is a good time to get rid of the returned pointer
//
Interop.Kernel32.LocalFree(ByteArray);
return 0;
Error:
resultSddl = null;
if (errorCode == Interop.Errors.ERROR_NOT_ENOUGH_MEMORY)
{
throw new OutOfMemoryException();
}
return errorCode;
}