Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C Windows Win32 programming , +
I want to set the name of my local host. I am using sethostname() function but I get an error as follows:
error C3861: 'sethostname': identifier not found.
Below is the code snippet:
 
WSADATA wsa;
///Initialise winsock///
if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
   {
      //Socket Initialization Failed///
      exit(EXIT_FAILURE);
   }
 char setname[128]="Ayesha-PC";
 sethostname(setname, sizeof (setname));
Posted 11-Apr-13 1:00am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Are you looking for SetComputerNameEx[^]?
  Permalink  
Comments
ayesha hassan at 11-Apr-13 8:06am
   
Thank you for the help, but this function changes the name of PC after the system is restarted while I want to change the name as soon as the function is called.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

According to the winsock documentation[^] there is no such function.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You probably have seen that as example in a Unix-based application. There the function sethostname exists, (although it would be called with strlen (name) as second argument, and not with sizeof (name).
 
For an equivalent in the Windows world, CPallini has given you already the correct link.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Afzaal Ahmad Zeeshan 82
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100