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 dnsapi, prefix the name with the module name and a period.
dnsquery (dnsapi)
.
C# Signature:
[DllImport("dnsapi", EntryPoint="DnsQuery_W", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
private static extern int DnsQuery([MarshalAs(UnmanagedType.VBByRefStr)]ref string pszName, QueryTypes wType, QueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved);
Private Declare Unicode Function DnsQuery Lib "dnsapi" Alias "DnsQuery_W" (<MarshalAs(UnmanagedType.VBByRefStr)> _
ByRef pszName As String, ByVal wType As QueryTypes, ByVal options As QueryOptions, ByVal aipServers As Integer, ByRef ppQueryResults As IntPtr, ByVal pReserved As Integer) As Integer
<DllImport("dnsapi", CharSet := CharSet.Auto, SetLastError := True)> _
Private Shared Sub DnsRecordListFree(ByVal pRecordList As IntPtr, ByVal FreeType As Integer)
End Sub
[StructLayout(LayoutKind.Sequential)]
private struct MXRecord
{
public IntPtr pNext;
public string pName;
public short wType;
public short wDataLength;
public int flags;
public int dwTtl;
public int dwReserved;
public IntPtr pNameExchange;
public short wPreference;
public short Pad;
}
[StructLayout(LayoutKind.Sequential)]
private struct MXRecord
{
public IntPtr pNext;
public string pName;
public short wType;
public short wDataLength;
public int flags;
public int dwTtl;
public int dwReserved;
public IntPtr pNameExchange;
public short wPreference;
public short Pad;
}
}
VB
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class DnsMx
Public Sub New()
End Sub
Private Declare Unicode Function DnsQuery Lib "dnsapi" Alias "DnsQuery_W" (<MarshalAs(UnmanagedType.VBByRefStr)> _
ByRef pszName As String, ByVal wType As QueryTypes, ByVal options As QueryOptions, ByVal aipServers As Integer, ByRef ppQueryResults As IntPtr, ByVal pReserved As Integer) As Integer
<DllImport("dnsapi", CharSet := Runtime.InteropServices.CharSet.Auto, SetLastError := True)> _
Private Shared Sub DnsRecordListFree(ByVal pRecordList As IntPtr, ByVal FreeType As Integer)
End Sub
Public Shared Function GetMXRecords(ByVal domain As String) As String()
Dim ptr1 As IntPtr = IntPtr.Zero
Dim ptr2 As IntPtr = IntPtr.Zero
Dim recMx As MXRecord
If Environment.OSVersion.Platform <> PlatformID.Win32NT Then
Throw New NotSupportedException()
End If
Dim list1 As New ArrayList()
Dim num1 As Integer = DnsMx.DnsQuery(domain, QueryTypes.DNS_TYPE_MX, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ptr1, 0)
If num1 <> 0 Then
Throw New Win32Exception(num1)
End If
ptr2 = ptr1
While Not ptr2.Equals(IntPtr.Zero)
recMx = DirectCast(Marshal.PtrToStructure(ptr2, GetType(MXRecord)), MXRecord)
If recMx.wType = 15 Then
Dim text1 As String = Marshal.PtrToStringAuto(recMx.pNameExchange)
list1.Add(text1)
End If
ptr2 = recMx.pNext
End While
DnsMx.DnsRecordListFree(ptr1, 0)
Return DirectCast(list1.ToArray(GetType(String)), String())
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure MXRecord
Public pNext As IntPtr
Public pName As String
Public wType As Short
Public wDataLength As Short
Public flags As Integer
Public dwTtl As Integer
Public dwReserved As Integer
Public pNameExchange As IntPtr
Public wPreference As Short
Public Pad As Short
End Structure
End Class
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).