How to get domain name using VC++

C, C++, Visual C++, C++.Net Topics
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to get domain name using VC++

Post by Neo » Sat Jan 09, 2010 2:21 pm

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 367 times
Post Reply

Return to “C/C++ Programming”