Click to See Complete Forum and Search --> : How can you get the comp name on windows?
Flamer
Feb 26th, 2001, 11:01 AM
does anyone know how to get the computer name from the network properties?
Vlatko
Feb 26th, 2001, 11:48 AM
#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;
parksie
Feb 26th, 2001, 12:10 PM
Change this:
char *buffer = new TCHAR[256];
to this:
TCHAR *buffer = new TCHAR[MAX_COMPUTERNAME_LENGTH];
Vlatko
Feb 26th, 2001, 12:59 PM
Ah , thans Parksie. I put the MAX_COMPUTERNAME_LENGTH in the code later so i forgot to change it in the buffer declaration.
Flamer
Feb 27th, 2001, 02:19 PM
Well the first one worked why the change?
Thanks again..
parksie
Feb 27th, 2001, 02:24 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.