Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DsMapSchemaGuids (ntdsapi)
 
.
Summary
TODO - a short description

C# Signature:

    [DllImport("Ntdsapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern uint DsMapSchemaGuids(
        IntPtr hDs,
        uint cGuids,
        Guid[] rGuids,
        out IntPtr ppGuidMap);

VB Signature:

    <DllImport("Ntdsapi.dll", CharSet := CharSet.Auto, SetLastError := True)> _
    Friend Shared Function DsMapSchemaGuids(hDs As IntPtr, cGuids As UInteger, rGuids As Guid(), ByRef ppGuidMap As IntPtr) As UInteger
    End Function

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Requires DsBind, recommend DsUnBind and DsFreeSchemaGuidMap

Tips & Tricks:

Please add some!

Sample Code:

    static void Main(string[] args)
    {
        string domainController = "domaincontroller.contoso.com";
        string domain = "contoso.com";

        IntPtr phDS = new IntPtr(0);
        IntPtr guidMap = new IntPtr(0);
        uint result;

        Guid[] myGuids = {
        new Guid("{e0fa1e69-9b45-11d0-afdd-00c04fd930c9}"),
        new Guid("{771727b1-31b8-4cdf-ae62-4fe39fadf89e}"),
        new Guid("{d5eb2eb7-be4e-463b-a214-634a44d7392e}"),
        new Guid("{e0fa1e8c-9b45-11d0-afdd-00c04fd930c9}")
        };

        //Result of 0 is successful.
        result = DsBind(domainController, domain, out phDS);

        if (result == 0)
        {
        result = DsMapSchemaGuids(phDS, (uint)myGuids.Length, myGuids, out guidMap);

        DS_SCHEMA_GUID_MAP[] guidMapResult = parseGuids(guidMap, myGuids.Length, true);
        for (int i = 0; i < guidMapResult.Length; i++)
        {
            Console.WriteLine("{0} = {1}", myGuids[i], guidMapResult[i].pName);
        }

        result = DsUnBind(phDS);
        }
        else
        {
        Console.WriteLine("Couldn't bind to the domain {0} on domain controller {1}.", domain, domainController);
        }
        Console.ReadKey();

    }

    [DllImport("Ntdsapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern uint DsMapSchemaGuids(
        IntPtr hDs,
        uint cGuids,
        Guid[] rGuids,
        out IntPtr ppGuidMap);

    [DllImport("Ntdsapi.dll", SetLastError = true)]
    internal static extern void DsFreeSchemaGuidMap(
        IntPtr pGuidMap);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    internal class GUID
    {
        internal uint Data1;
        internal int Data2;
        internal int Data3;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        internal byte[] Data4 = new byte[8];
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    internal struct DS_SCHEMA_GUID_MAP
    {
        internal GUID guid;
        internal uint guidType;
        internal string pName;
    }

    [DllImport("ntdsapi.dll", CharSet = CharSet.Auto)]
    static public extern uint DsBind(
      string DomainControllerName,
      string DnsDomainName,
      out IntPtr phDS);

    [DllImport("ntdsapi.dll", CharSet = CharSet.Auto)]
    static extern uint DsUnBind(
        IntPtr phDS);

    private static DS_SCHEMA_GUID_MAP[] parseGuids(IntPtr guidMap, int numGuids, bool freePointer)
    {
        int typeSize = Marshal.SizeOf(typeof(DS_SCHEMA_GUID_MAP));
        DS_SCHEMA_GUID_MAP[] schemaMap = new DS_SCHEMA_GUID_MAP[numGuids];
        IntPtr guidPointer = guidMap;

        for (int i = 0; i < numGuids; i++)
        {
        schemaMap[i] = (DS_SCHEMA_GUID_MAP)Marshal.PtrToStructure(
            new IntPtr
            (
                (long)guidPointer + i * typeSize
            ),
                typeof(DS_SCHEMA_GUID_MAP)
            );
        }

        if (freePointer)
        {
        DsFreeSchemaGuidMap(guidPointer);
        }

        return schemaMap;
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions