C#에서 AllocateAndInitializeSid 함수를 호출하는 방법은 무엇입니까?
문제
누군가 나에게 전화하는 완전하고 실제적인 예를 줄 수 있습니까? 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/호출 Interop 도우미:
[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);
}
다른 팁
.NET 2.0 이상을 대상으로 하는 경우 System.Security.Principal.SecurityIdentifier 클래스를 사용하면 SID를 래핑하여 오류가 발생하기 쉬운 Win32 API를 방지할 수 있습니다.
귀하의 질문에 대한 정확한 답변은 아니지만 그것이 유용할 수 있다는 것을 누가 알겠습니까?
Platform Invoke의 경우 www.pinvoke.net이 여러분의 새로운 가장 친한 친구입니다!
http://www.pinvoke.net/default.aspx/advapi32/AllocateAndInitializeSid.html
제휴하지 않습니다 StackOverflow