OBJECT_ATTRIBUTES (Structures)
Last changed: -113.200.84.43

.
Summary
The OBJECT_ATTRIBUTES structure specifies attributes that can be applied to objects or object handles by routines that create objects and/or return handles to objects.

VB.NET Definition:

<StructLayout(LayoutKind.Sequential)> _
Public Structure OBJECT_ATTRIBUTES
    Implements IDisposable
    Public Length As Integer
    Public RootDirectory As IntPtr
    Private m_objectName As IntPtr
    Public Attributes As UInteger
    Public SecurityDescriptor As IntPtr
    Public SecurityQualityOfService As IntPtr

    Public Sub New(name As String, attrs As UInteger)
        Length = 0
        RootDirectory = IntPtr.Zero
        m_objectName = IntPtr.Zero
        Attributes = attrs
        SecurityDescriptor = IntPtr.Zero
        SecurityQualityOfService = IntPtr.Zero

        Length = Marshal.SizeOf(Me)
        ObjectName = New UNICODE_STRING(name)
    End Sub

    Public Property ObjectName As UNICODE_STRING
        Get
            Return DirectCast(Marshal.PtrToStructure(m_objectName, GetType(UNICODE_STRING)), UNICODE_STRING)
        End Get

        Set
            Dim fDeleteOld As Boolean = m_objectName <> IntPtr.Zero
            If Not fDeleteOld Then
                m_objectName = Marshal.AllocHGlobal(Marshal.SizeOf(value))
            End If
            Marshal.StructureToPtr(value, m_objectName, fDeleteOld)
        End Set
    End Property

    Public Sub Dispose()
        If m_objectName <> IntPtr.Zero Then
            Marshal.DestroyStructure(m_objectName, GetType(UNICODE_STRING))
            Marshal.FreeHGlobal(m_objectName)
            m_objectName = IntPtr.Zero
        End If
    End Sub
End Structure

C# Definition:

[StructLayout(LayoutKind.Sequential)]
public struct OBJECT_ATTRIBUTES : IDisposable
{
   public int Length;
   public IntPtr RootDirectory;
   private IntPtr objectName;
   public uint Attributes;
   public IntPtr SecurityDescriptor;
   public IntPtr SecurityQualityOfService;

   public OBJECT_ATTRIBUTES(string name, uint attrs)
   {
     Length = 0;
     RootDirectory = IntPtr.Zero;
     objectName = IntPtr.Zero;
     Attributes = attrs;
     SecurityDescriptor = IntPtr.Zero;
     SecurityQualityOfService = IntPtr.Zero;

     Length = Marshal.SizeOf(this);
     ObjectName = new UNICODE_STRING(name);
   }

   public UNICODE_STRING ObjectName
   {
     get
     {
      return (UNICODE_STRING)Marshal.PtrToStructure(
       objectName, typeof(UNICODE_STRING));
     }

     set
     {
      bool fDeleteOld = objectName != IntPtr.Zero;
      if (!fDeleteOld)
       objectName = Marshal.AllocHGlobal(Marshal.SizeOf(value));
      Marshal.StructureToPtr(value, objectName, fDeleteOld);
     }
   }

   public void Dispose()
   {
     if (objectName != IntPtr.Zero)
     {
       Marshal.DestroyStructure(objectName, typeof(UNICODE_STRING));
       Marshal.FreeHGlobal(objectName);
       objectName = IntPtr.Zero;
     }
   }
}

User-Defined Field Types:

UNICODE_STRING

Notes:

None.

Documentation