Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
DsGetDcNext (netapi32)
.
C# Signature:
using HANDLE = System.IntPtr;
using DWORD = System.UInt32;
[DllImport("netapi32.dll", SetLastError=true)]
internal static extern DWORD DsGetDcNext(
HANDLE GetDcContextHandle,
IntPtr SockAddressCount,
IntPtr SockAddresses, //must free this if using (SocketAddressCount > 1)
out IntPtr DnsHostName //will have to marshal this one manually
);
For Example #2 Below:
[DllImport("Netapi32.dll", EntryPoint = "DsGetDcNextW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
internal static extern int DsGetDcNext([In] IntPtr getDcContextHandle,
[In, Out] ref IntPtr sockAddressCount,
out IntPtr sockAdresses, out IntPtr dnsHostName);
VB Signature:
Declare Function DsGetDcNext Lib "netapi32.dll" (TODO) As TODO
[out, optional] Pointer to a ULONG value that receives the number of elements in the SockAddresses array. If this parameter is NULL, socket addresses are not retrieved.
[out, optional] Pointer to an array of SOCKET_ADDRESS structures that receives the socket address data for the domain controller. SockAddressCount receives the number of elements in this array.
All returned addresses will be of type AF_INET or AF_INET6. The sin_port member contains the port from the server record. A port of 0 indicates no port is available from DNS.
The caller must free this memory when it is no longer required by calling LocalFree.
[out, optional] Pointer to a string pointer that receives the DNS name of the domain controller. This parameter receives NULL if no host name is known. The caller must free this memory when it is no longer required by calling NetApiBufferFree.
Tips & Tricks:
Please add some!
Sample Code:
bool endLoop = false;
ArrayList al = new ArrayList();
while (!endLoop)
{
IntPtr pDnsHostName = IntPtr.Zero;
//check the return code
switch (rc)
{
case 259: //ERROR_NO_MORE_ITEMS
endLoop = true;
break;
case 0: //ERROR_SUCCESS
al.Add(Marshal.PtrToStringAuto(pDnsHostName));
break;
case ERROR_FILEMARK_DETECTED: //127 - I think...
break;
default:
throw new Win32Exception(); //internally calls GetLastWin32Error()
break;
}
}
finally
{
if (!Win32.IsNullHandle(pDnsHostName)) //pNnsHostName != IntPtr.Zero;
NativeMethods.NetApiBufferFree(pDnsHostName);
}
}
Example #2
bool endLoop = false;
IntPtr pDcContext = new IntPtr();
int iReturn = 0;
try
{
Console.WriteLine("Open");
// leave the second parameter set to 0 and "MYADSITE" set to null if you want the entire domain
iReturn = DsGetDcOpen("domain1.mydomains.com", 1, "MYADSITE", (System.IntPtr)null, null, 0, out pDcContext);
Console.WriteLine("Enum " + iReturn.ToString());
IntPtr pDnsHostName = IntPtr.Zero;
while (!endLoop)
{
pDnsHostName = IntPtr.Zero;
The DsGetDcNext function retrieves the next domain controller in a domain controller enumeration operation.
11/3/2011 10:32:57 AM - dcray2000@hotmail.com-192.223.163.5
The DsGetDcOpen function opens a new domain controller enumeration operation
10/11/2007 11:16:43 AM - dcray2000@hotmail.com-192.223.163.5
The SOCKET_ADDRESS structure stores protocol-specific address information.
11/3/2011 10:31:15 AM - anonymous
Frees the specified local memory object and invalidates its handle.
8/27/2008 3:05:46 PM - -151.145.238.91
Frees the memory allocated by network management functions.
6/21/2016 8:26:32 AM - -63.226.251.37
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).