Results 1 to 8 of 8

Thread: [2.0] Struct Problem

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    [2.0] Struct Problem

    C# Code:
    1. [StructLayout(LayoutKind.Sequential)]
    2.     private struct TOKEN_PRIVILEGES{
    3.     private int PrivilegeCount;
    4.     private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
    5. }

    I am getting the following, "Identifier Expected on the last line in that struct any ideas what could be causing it?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2.0] Struct Problem

    Privileges(ANYSIZE_ARRAY) - If that's meant to be an array, should you not be specifying the size with LUID_AND_ATTRIBUTES? If this is a bit of constructor logic, then you can give your struct a constructor in which set Privileges to be whatever you want.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Struct Problem

    One of the differences between classes and structures is that you're not allowed to initialise members when you declare them. Specifying the size of an array creates an object, so that would initialise an array variable.

    That said, your code makes no sense. This line:
    Code:
    private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
    Isn't valid syntax for anything. It's not specifying the size of an array and it's not passing a parameter to a constructor. What exactly was the intention?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Struct Problem

    Code:
    private const int SECURITY_DESCRIPTOR_REVISION = (1);
            private const int OWNER_SECURITY_INFORMATION = 0x1;
            private const int TOKEN_ASSIGN_PRIMARY = 0x1;
            private const int TOKEN_DUPLICATE = 0x2;
            private const int TOKEN_IMPERSONATE = 0x4;
            private const int TOKEN_QUERY = 0x8;
            private const int TOKEN_QUERY_SOURCE = 0x10;
            private const int TOKEN_ADJUST_PRIVILEGES = 0x20;
            private const int TOKEN_ADJUST_GROUPS = 0x40;
            private const int TOKEN_ADJUST_DEFAULT = 0x80;
            private const int TOKEN_ALL_ACCESS =  TOKEN_ASSIGN_PRIMARY + TOKEN_DUPLICATE + TOKEN_IMPERSONATE + TOKEN_QUERY + TOKEN_QUERY_SOURCE + TOKEN_ADJUST_PRIVILEGES + TOKEN_ADJUST_GROUPS + TOKEN_ADJUST_DEFAULT;
            private const int ANYSIZE_ARRAY = 1;
            private const string SE_RESTORE_NAME = "SeRestorePrivilege";
            private const int SE_PRIVILEGE_ENABLED = 0x2;
        
            [StructLayout(LayoutKind.Sequential)]
            private struct ACL{
    	        private byte AclRevision;
    	        private byte Sbz1;
    	        private Int16 AclSize;
    	        private Int16 AceCount;
    	        private Int16 Sbz2;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            private struct SECURITY_DESCRIPTOR{
    	        private byte Revision;
    	        private byte Sbz1;
    	        private int Control;
    	        private int Owner;
    	        private int Group;
    	        private ACL Sacl;
    	        private ACL Dacl;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            private struct LARGE_INTEGER{
    	        private int lowpart;
    	        private int highpart;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            private struct LUID{
    	        private int LowPart;
    	        private int HighPart;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            private struct LUID_AND_ATTRIBUTES{
    	        private LUID pLuid;
    	        private int Attributes;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            private struct TOKEN_PRIVILEGES{
    	        private int PrivilegeCount;
    	        private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
            }
    That is all the stuff in question...

    ANYSIZE_ARRAY is equal to 1. http://support.microsoft.com/kb/318744 that is the link i need to convert, yes i know there are easier ways probably using the DirectoryInfo and FileInfo classes to change the privileges but it is a must for other reasons that i use API.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Struct Problem

    First of all, you've declared all your structure fields private. That's no use at all because it means you can never access any of them. Structure fields are public by default, so you need to either omit an access modifier or, preferably, declare all your fields public.

    Secondly, this:
    CSharp Code:
    1. private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
    is not an array declaration in C#. This:
    vb Code:
    1. Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
    would translate to this:
    Code:
    LUID_AND_ATTRIBUTES Privileges = new LUID_AND_ATTRIBUTES[ANYSIZE_ARRAY];
    As we said though, you cannot initialise fields when you declare them in structures. You either need to use a constructor to create the array or else do it from outside the object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Struct Problem

    I changed all the fields in the structs to public and it appears i am receiving more errors now invalid arguements in the API calls etc..

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2.0] Struct Problem

    Then you need to pass valid arguments to the API functions. With such a vague description of the issue I can't be any more specific with the solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2.0] Struct Problem

    Show your code as you update it. Did you add the constructor?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width