C++与C#类型转换例子

22 篇文章 2 订阅

C++部分类型定义:

typedef struct _SID_AND_ATTRIBUTES_HASH {
    DWORD SidCount;
    PSID_AND_ATTRIBUTES SidAttr;
    SID_HASH_ENTRY Hash[SID_HASH_SIZE];
} SID_AND_ATTRIBUTES_HASH, *PSID_AND_ATTRIBUTES_HASH;

 

typedef struct _LUID {
    DWORD LowPart;
    LONG HighPart;
} LUID, *PLUID;

 

typedef enum _TOKEN_TYPE {
    TokenPrimary = 1,
    TokenImpersonation
    } TOKEN_TYPE;
typedef TOKEN_TYPE *PTOKEN_TYPE;

 

typedef enum _SECURITY_IMPERSONATION_LEVEL {
    SecurityAnonymous,
    SecurityIdentification,
    SecurityImpersonation,
    SecurityDelegation
    } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;

 

typedef PVOID PSID;

 

///

C++要转换的类型:

struct TOKEN_ACCESS_INFORMATION {
  
   
    PTOKEN_PRIVILEGES Privileges;  //结构体指针
    LUID AuthenticationId;    //结构体
    TOKEN_TYPE TokenType;    //枚举类型enum
    SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;  //枚举类型enum
   
    DWORD Flags;
    DWORD AppContainerNumber;
    PSID PackageSid;
    PSID TrustLevelSid;
};

 

///

C#对应的类型:

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct TOKEN_ACCESS_INFORMATION {
    
    /// PTOKEN_PRIVILEGES->_TOKEN_PRIVILEGES*
    public System.IntPtr Privileges;
    
    /// LUID->_LUID
    public LUID AuthenticationId;
    
    /// TOKEN_TYPE->_TOKEN_TYPE
    public TOKEN_TYPE TokenType;
    
    /// SECURITY_IMPERSONATION_LEVEL->_SECURITY_IMPERSONATION_LEVEL
    public SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
    
    /// DWORD->unsigned int
    public uint Flags;
    
    /// DWORD->unsigned int
    public uint AppContainerNumber;
    
    /// PSID->PVOID->void*
    public System.IntPtr PackageSid;
    
    /// PSID->PVOID->void*
    public System.IntPtr TrustLevelSid;
}

 

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct LUID {
    
    /// DWORD->unsigned int
    public uint LowPart;
    
    /// LONG->int
    public int HighPart;
}

public enum TOKEN_TYPE {
    
    /// TokenPrimary -> 1
    TokenPrimary = 1,
    
    TokenImpersonation,
}

public enum SECURITY_IMPERSONATION_LEVEL {
    
    SecurityAnonymous,
    
    SecurityIdentification,
    
    SecurityImpersonation,
    
    SecurityDelegation,
}

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct TOKEN_PRIVILEGES {
    
    /// DWORD->unsigned int
    public uint PrivilegeCount;
    
    /// LUID_AND_ATTRIBUTES[1]
    [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=1, ArraySubType=System.Runtime.InteropServices.UnmanagedType.Struct)]
    public LUID_AND_ATTRIBUTES[] Privileges;
}

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct LUID_AND_ATTRIBUTES {
    
    /// LUID->_LUID
    public LUID Luid;
    
    /// DWORD->unsigned int
    public uint Attributes;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值