does anyone know how to get the computer name from the network properties?
Printable View
does anyone know how to get the computer name from the network properties?
Code:#include <windows.h>
#include <iostream.h>
char *buffer = new TCHAR[256];
DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
GetComputerName(buffer,&len);
//buffer contains computer name
cout<<buffer<<endl;
Change this:
char *buffer = new TCHAR[256];
to this:
TCHAR *buffer = new TCHAR[MAX_COMPUTERNAME_LENGTH];
Ah , thans Parksie. I put the MAX_COMPUTERNAME_LENGTH in the code later so i forgot to change it in the buffer declaration.
Well the first one worked why the change?
Thanks again..
Okay...normally TCHAR resolves to char. However, if you compile for Unicode it resolves to wchar_t, which is two bytes. So, normally it's fine.
That's the obscure one gone... ;)
The other change was just to match the buffer sizes.