Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to pass a structure contains an array in any size ?

How to pass a structure contains an array in any size ?

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structurestutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Ky Nam
    wrote on last edited by
    #1

    Hi I want to use this structure in AdjustTokenPrivileges(...)

    typedef struct _TOKEN_PRIVILEGES {
    DWORD PrivilegeCount;
    LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
    } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;

    How to declare it in .NET ?

    D 1 Reply Last reply
    0
    • K Ky Nam

      Hi I want to use this structure in AdjustTokenPrivileges(...)

      typedef struct _TOKEN_PRIVILEGES {
      DWORD PrivilegeCount;
      LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
      } TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;

      How to declare it in .NET ?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I take it you're trying to call ExitWindows, or ExitWindowsEx?? Try this[^]...

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      K 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I take it you're trying to call ExitWindows, or ExitWindowsEx?? Try this[^]...

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        K Offline
        K Offline
        Ky Nam
        wrote on last edited by
        #3

        Thank you for your reply I have used this structure for years , but I just want to know how to declare it like C++ Now I'm using this approach

        Public Class SePrivilege
            Public Const SeCount As Integer = 35
            Public Const SeCreateTokenPrivilege As String = "SeCreateTokenPrivilege"
            Public Const SeAssignPrimaryTokenPrivilege As String = "SeAssignPrimaryTokenPrivilege"
            Public Const SeLockMemoryPrivilege As String = "SeLockMemoryPrivilege"
            Public Const SeIncreaseQuotaPrivilege As String = "SeIncreaseQuotaPrivilege"
            Public Const SeUnsolicitedInputPrivilege As String = "SeUnsolicitedInputPrivilege"
            Public Const SeMachineAccountPrivilege As String = "SeMachineAccountPrivilege"
            Public Const SeTcbPrivilege As String = "SeTcbPrivilege"
            Public Const SeSecurityPrivilege As String = "SeSecurityPrivilege"
            Public Const SeTakeOwnershipPrivilege As String = "SeTakeOwnershipPrivilege"
            Public Const SeLoadDriverPrivilege As String = "SeLoadDriverPrivilege"
            Public Const SeSystemProfilePrivilege As String = "SeSystemProfilePrivilege"
            Public Const SeSystemtimePrivilege As String = "SeSystemtimePrivilege"
            Public Const SeProfileSingleProcessPrivilege As String = "SeProfileSingleProcessPrivilege"
            Public Const SeIncreaseBasePriorityPrivilege As String = "SeIncreaseBasePriorityPrivilege"
            Public Const SeCreatePagefilePrivilege As String = "SeCreatePagefilePrivilege"
            Public Const SeCreatePermanentPrivilege As String = "SeCreatePermanentPrivilege"
            Public Const SeBackupPrivilege As String = "SeBackupPrivilege"
            Public Const SeRestorePrivilege As String = "SeRestorePrivilege"
            Public Const SeShutdownPrivilege As String = "SeShutdownPrivilege"
            Public Const SeDebugPrivilege As String = "SeDebugPrivilege"
            Public Const SeAuditPrivilege As String = "SeAuditPrivilege"
            Public Const SeSystemEnvironmentPrivilege As String = "SeSystemEnvironmentPrivilege"
            Public Const SeChangeNotifyPrivilege As String = "SeChangeNotifyPrivilege"
            Public Const SeRemoteShutdownPrivilege As String = "SeRemoteShutdownPrivilege"
            Public Const SeUndockPrivilege As String = "SeUndockPrivilege"
            Public Const SeSyncAgentPrivilege As String = "SeSyncAgentPrivilege"
            Public Const SeEnableDelegationPrivilege As String = "SeEnableDelegationPrivilege"
            Public Const SeManageVolumePrivilege As String = "SeManageVolumePrivilege
        
        D 1 Reply Last reply
        0
        • K Ky Nam

          Thank you for your reply I have used this structure for years , but I just want to know how to declare it like C++ Now I'm using this approach

          Public Class SePrivilege
              Public Const SeCount As Integer = 35
              Public Const SeCreateTokenPrivilege As String = "SeCreateTokenPrivilege"
              Public Const SeAssignPrimaryTokenPrivilege As String = "SeAssignPrimaryTokenPrivilege"
              Public Const SeLockMemoryPrivilege As String = "SeLockMemoryPrivilege"
              Public Const SeIncreaseQuotaPrivilege As String = "SeIncreaseQuotaPrivilege"
              Public Const SeUnsolicitedInputPrivilege As String = "SeUnsolicitedInputPrivilege"
              Public Const SeMachineAccountPrivilege As String = "SeMachineAccountPrivilege"
              Public Const SeTcbPrivilege As String = "SeTcbPrivilege"
              Public Const SeSecurityPrivilege As String = "SeSecurityPrivilege"
              Public Const SeTakeOwnershipPrivilege As String = "SeTakeOwnershipPrivilege"
              Public Const SeLoadDriverPrivilege As String = "SeLoadDriverPrivilege"
              Public Const SeSystemProfilePrivilege As String = "SeSystemProfilePrivilege"
              Public Const SeSystemtimePrivilege As String = "SeSystemtimePrivilege"
              Public Const SeProfileSingleProcessPrivilege As String = "SeProfileSingleProcessPrivilege"
              Public Const SeIncreaseBasePriorityPrivilege As String = "SeIncreaseBasePriorityPrivilege"
              Public Const SeCreatePagefilePrivilege As String = "SeCreatePagefilePrivilege"
              Public Const SeCreatePermanentPrivilege As String = "SeCreatePermanentPrivilege"
              Public Const SeBackupPrivilege As String = "SeBackupPrivilege"
              Public Const SeRestorePrivilege As String = "SeRestorePrivilege"
              Public Const SeShutdownPrivilege As String = "SeShutdownPrivilege"
              Public Const SeDebugPrivilege As String = "SeDebugPrivilege"
              Public Const SeAuditPrivilege As String = "SeAuditPrivilege"
              Public Const SeSystemEnvironmentPrivilege As String = "SeSystemEnvironmentPrivilege"
              Public Const SeChangeNotifyPrivilege As String = "SeChangeNotifyPrivilege"
              Public Const SeRemoteShutdownPrivilege As String = "SeRemoteShutdownPrivilege"
              Public Const SeUndockPrivilege As String = "SeUndockPrivilege"
              Public Const SeSyncAgentPrivilege As String = "SeSyncAgentPrivilege"
              Public Const SeEnableDelegationPrivilege As String = "SeEnableDelegationPrivilege"
              Public Const SeManageVolumePrivilege As String = "SeManageVolumePrivilege
          
          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Time is a bit short for me right now. I've got a switch/fiber problem I'm working. In a brief "wait for the other guy" moment, I've managed to come up with this[^]. See what you can get from this example, just under half way down the page.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          K 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Time is a bit short for me right now. I've got a switch/fiber problem I'm working. In a brief "wait for the other guy" moment, I've managed to come up with this[^]. See what you can get from this example, just under half way down the page.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            K Offline
            K Offline
            Ky Nam
            wrote on last edited by
            #5

            It just works :)

            Public Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal tokenhandle As IntPtr, ByVal disableprivs As Boolean, ByVal Newstate As IntPtr, ByVal bufferlength As Integer, ByVal PreivousState As TokenPrivileges, ByRef Returnlength As Integer) As Boolean

            Public Class TokenPrivileges
                Inherits List(Of LUIDAndAttributes)
                Implements IDisposable
            
                Dim P As IntPtr
            
                Public Function AllocHGlobal() As IntPtr
                    FreeHGlobal()
            
                    P = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Integer)) + Marshal.SizeOf(GetType(LUIDAndAttributes)) \* Count)
                    Dim P2 As IntPtr = P
            
                    Marshal.WriteInt32(P2, 0, Count)
                    P2 = Sum(P2, Marshal.SizeOf(Count.GetType))
            
                    For Each LUIDAndAttributes As LUIDAndAttributes In Me
                        Marshal.StructureToPtr(LUIDAndAttributes, P2, False)
                        P2 = Sum(P2, Marshal.SizeOf(LUIDAndAttributes.GetType))
                    Next
            
                    Return P
                End Function
            
                Public Sub FreeHGlobal()
                    If P <> IntPtr.Zero Then
                        Marshal.FreeHGlobal(P)
                        P = IntPtr.Zero
                    End If
                End Sub
            
            End Class
            
            Public Shared Function Sum(ByVal P As IntPtr, ByVal I As Integer) As IntPtr
                If IntPtr.Size = 4 Then
                    Return New IntPtr(P.ToInt32 + I)
                Else
                    Return New IntPtr(P.ToInt64 + I)
                End If
            End Function
            
            D 1 Reply Last reply
            0
            • K Ky Nam

              It just works :)

              Public Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal tokenhandle As IntPtr, ByVal disableprivs As Boolean, ByVal Newstate As IntPtr, ByVal bufferlength As Integer, ByVal PreivousState As TokenPrivileges, ByRef Returnlength As Integer) As Boolean

              Public Class TokenPrivileges
                  Inherits List(Of LUIDAndAttributes)
                  Implements IDisposable
              
                  Dim P As IntPtr
              
                  Public Function AllocHGlobal() As IntPtr
                      FreeHGlobal()
              
                      P = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Integer)) + Marshal.SizeOf(GetType(LUIDAndAttributes)) \* Count)
                      Dim P2 As IntPtr = P
              
                      Marshal.WriteInt32(P2, 0, Count)
                      P2 = Sum(P2, Marshal.SizeOf(Count.GetType))
              
                      For Each LUIDAndAttributes As LUIDAndAttributes In Me
                          Marshal.StructureToPtr(LUIDAndAttributes, P2, False)
                          P2 = Sum(P2, Marshal.SizeOf(LUIDAndAttributes.GetType))
                      Next
              
                      Return P
                  End Function
              
                  Public Sub FreeHGlobal()
                      If P <> IntPtr.Zero Then
                          Marshal.FreeHGlobal(P)
                          P = IntPtr.Zero
                      End If
                  End Sub
              
              End Class
              
              Public Shared Function Sum(ByVal P As IntPtr, ByVal I As Integer) As IntPtr
                  If IntPtr.Size = 4 Then
                      Return New IntPtr(P.ToInt32 + I)
                  Else
                      Return New IntPtr(P.ToInt64 + I)
                  End If
              End Function
              
              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I wish I had the time to play around around with the code myself. Glad it works for you though!

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups