Page 1 of 1

How to get domain name using VC++

Posted: Sat Jan 09, 2010 2:21 pm
by Neo
To get domain name, you will need to use following method with the two files in attached zip file.
The lib file must be linked to the project using Settings->Link->General and the header file can be placed to project folder.

Code: Select all

#include <windows.h>
#include "Windns.h"
#include <iostream>
 
int main()
{
	char sDomainName[100];
	DWORD size = 100;
 
	DNS_STATUS res = DnsQueryConfig(
		DnsConfigFullHostName_A,
		FALSE,
		NULL,
		NULL,
		sDomainName,
		&size
	);
 
	std::cout << sDomainName << std::endl;
 
	return 0;
}
DNS.zip
(9.69 KiB) Downloaded 432 times