Structs for externals

Hi,

I cannot seem to figure out how to fix this particular issue.

My C# application imports a series of Win32 API externals, from various system DLLs.

Some of these imported Win32 API imports require specific structs (amongst other things) to be created.

Take for example:

        [DllImport("advapi32.dll", SetLastError=true)]
        
        public static extern bool AdjustTokenPrivileges(
            IntPtr TokenHandle,
            bool DisableAllPrivileges,
            ref TOKEN_PRIVILEGES NewState,
            UInt32 BufferLengthInBytes,
            int PreviousState,
            int ReturnLengthInBytes);

Note the TOKEN_PRIVILEGES in the definition of the extern, it is not directly supported by C#, so it needs to be created:


        
        public struct TOKEN_PRIVILEGES
        {
            public UInt32 PrivilegeCount;
            public LUID Luid;
            public UInt32 Attributes;
        }

All of this is no problem for C#, of course, works as it should.

The problem i am running into with ReSharper is that the above declaration of TOKEN_PRIVILEGES ('public struct TOKEN_PRIVILEGES', as it is defined within the advapi32 header file, with all capitals and the underscore, it is only smart to define it the same way and shape within C#)  and a whole host,
some 15+, of other structures of similar use are giving me 'Name "TOKEN_PRIVILEGES" does not match rule "Types and mamespaces". Suggested...]]>' warnings. Another issue, related is that similar structs with an uppercase name, but without underscores, throw similar warnings, THOSE i can 'add to th
e dictionary of abbreviations' though. Not so with the underscore using ones.

Sure, it is correct, I use UpperCamelCase for, say 'public class FooBar'. But i am left with the options to leave the warnings there (pretty annoying at times), or use 'comments' to ignore them, both are NOT what i am looking for.

Is it possible to 'single out' these structs and have them be exceptions to the rule?

Thanks,

Mike

---
Original message URL: http://www.jetbrains.net/devnet/message/5240466#5240466

Please sign in to leave a comment.