|
-
Apr 3rd, 2008, 10:59 PM
#1
Thread Starter
Interweb adm/o/distrator
[2.0] Struct Problem
C# Code:
[StructLayout(LayoutKind.Sequential)]
private struct TOKEN_PRIVILEGES{
private int PrivilegeCount;
private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
}
I am getting the following, "Identifier Expected on the last line in that struct any ideas what could be causing it?
-
Apr 4th, 2008, 03:32 PM
#2
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.
-
Apr 4th, 2008, 09:27 PM
#3
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?
-
Apr 5th, 2008, 02:18 AM
#4
Thread Starter
Interweb adm/o/distrator
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.
-
Apr 5th, 2008, 02:49 AM
#5
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:
private LUID_AND_ATTRIBUTES Privileges(ANYSIZE_ARRAY);
is not an array declaration in C#. This:
vb Code:
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.
-
Apr 5th, 2008, 03:14 AM
#6
Thread Starter
Interweb adm/o/distrator
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..
-
Apr 5th, 2008, 09:37 AM
#7
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.
-
Apr 6th, 2008, 01:11 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|