« December 2005 »
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
You are not logged in. Log in

Programming Tips
Tuesday, 20 December 2005
To retrieve the machine name
Mood:  hungry
Topic: VC++
It is easy to get the name of a machine. Make sure your application supports "winsock"


      WSADATA WSAData;
      ::ZeroMemory(&WSAData, sizeof(WSAData));
      //init winsock
      ::WSAStartup(MAKEWORD(1,0), &WSAData);

Now get the host name:

      char szHostName[MAX_PATH];
      ::gethostname(szHostName, MAX_PATH);

szHostName has got the host name

Now close winsock.

      //close winsock
      ::WSACleanup();

Posted by Nibu babu thomas at 1:33 PM
Updated: Tuesday, 20 December 2005 1:38 PM

View Latest Entries