如何叫AllocateAndInitializeSid能从C#?
题
有人能给我一个完整和工作实例的呼吁 AllocateAndInitializeSid
能从C#代码?
我找到了 此:
BOOL WINAPI AllocateAndInitializeSid(
__in PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
__in BYTE nSubAuthorityCount,
__in DWORD dwSubAuthority0,
__in DWORD dwSubAuthority1,
__in DWORD dwSubAuthority2,
__in DWORD dwSubAuthority3,
__in DWORD dwSubAuthority4,
__in DWORD dwSubAuthority5,
__in DWORD dwSubAuthority6,
__in DWORD dwSubAuthority7,
__out PSID *pSid
);
我不知道如何构建的签名这种方法的-我应该怎么做 PSID_IDENTIFIER_AUTHORITY
和 PSID
类型?我应该怎样通过他们使用 ref
或 out
?
解决方案
使用 P/调用互操作助理:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct SidIdentifierAuthority {
/// BYTE[6]
[System.Runtime.InteropServices.MarshalAsAttribute(
System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst = 6,
ArraySubType =
System.Runtime.InteropServices.UnmanagedType.I1)]
public byte[] Value;
}
public partial class NativeMethods {
/// Return Type: BOOL->int
///pIdentifierAuthority: PSID_IDENTIFIER_AUTHORITY->_SID_IDENTIFIER_AUTHORITY*
///nSubAuthorityCount: BYTE->unsigned char
///nSubAuthority0: DWORD->unsigned int
///nSubAuthority1: DWORD->unsigned int
///nSubAuthority2: DWORD->unsigned int
///nSubAuthority3: DWORD->unsigned int
///nSubAuthority4: DWORD->unsigned int
///nSubAuthority5: DWORD->unsigned int
///nSubAuthority6: DWORD->unsigned int
///nSubAuthority7: DWORD->unsigned int
///pSid: PSID*
[System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "AllocateAndInitializeSid")]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool AllocateAndInitializeSid(
[System.Runtime.InteropServices.InAttribute()]
ref SidIdentifierAuthority pIdentifierAuthority,
byte nSubAuthorityCount,
uint nSubAuthority0,
uint nSubAuthority1,
uint nSubAuthority2,
uint nSubAuthority3,
uint nSubAuthority4,
uint nSubAuthority5,
uint nSubAuthority6,
uint nSubAuthority7,
out System.IntPtr pSid);
}
其他提示
如果你的目标。网2.0或后来,这类系统。安全。校长。SecurityIdentifier包SID和可以避免的错误易Win32Api。
不完全是一个回答你的问题,但是谁知道这可能是有用的。
对于平台的调用www.pinvoke.net 是你最好的朋友!
http://www.pinvoke.net/default.aspx/advapi32/AllocateAndInitializeSid.html
不隶属于 StackOverflow