質問

誰かが私に、 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);

    }

他のヒント

.NET 2.0 以降をターゲットにしている場合は、System.Security.Principal.SecurityIdentifier クラスで SID をラップし、エラーが発生しやすい Win32 API を回避できます。

あなたの質問に対する正確な答えではありませんが、役に立つかもしれません。

Platform Invoke の場合、www.pinvoke.net があなたの新しい親友です。

http://www.pinvoke.net/default.aspx/advapi32/AllocateAndInitializeSid.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top