Need help translating C _TRUSTEE_W typedef to C# struct

93 views Asked by At

I am looking to use the GetEffectiveRightsFromAclW Win32 function in .NET Framework. One of the parameters is of type PTRUSTEE_W. Insofar as what I've come across, this is a rather complex C type:

typedef struct _TRUSTEE_W {
  struct _TRUSTEE_W          *pMultipleTrustee;
  MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
  TRUSTEE_FORM               TrusteeForm;
  TRUSTEE_TYPE               TrusteeType;
  union {
    LPWSTR             ptstrName;
    SID                *pSid;
    OBJECTS_AND_SID    *pObjectsAndSid;
    OBJECTS_AND_NAME_W *pObjectsAndName;
  };
  LPWCH                      ptstrName;
} TRUSTEE_W, *PTRUSTEE_W, TRUSTEEW, *PTRUSTEEW;

I'm stuck on 3 main fronts:

  • My understanding of a C union is that any of the parameters defined within a union may be used to populate the field at that position in the struct. Am I understanding that correctly?
  • The parameter name ptstrName appears twice, once within the union and once at the end. Each instance has a different type (LPSTR and LPCH). What does this mean, exactly?
  • I have absolutely no idea what the last line of this typedef (after the final closing brace) means
    TRUSTEE_W, *PTRUSTEE_W, TRUSTEEW, *PTRUSTEEW;

I did make an attempt, which did not work (this is assuming x64 architecture, so I'm incrementing the offset by 8 instead of 4; let me know if that's wrong):

struct Trustee {
    [FieldOffset(0)] IntPtr pMultipleTrustee;
    [FieldOffset(8)] int MultipleTrusteeOperation;
    [FieldOffset(16)] int TrusteeForm;
    [FieldOffset(24)] int TrusteeType;
    [FieldOffset(32)] string ptstrName;
    [FieldOffset(32)] IntPtr pSid;
    [FieldOffset(32)] IntPtr pObjectsAndSid;
    [FieldOffset(32)] IntPtr pObjectsAndName;
};
1

There are 1 answers

0
Mike Bruno On

I was able to find what I needed on pinvoke.net

I'm not marking this as the authoritative answer since I don't have the function actually working yet. Return code is: (0x80004005): The parameter is incorrect