🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11274

Problem with GetComputerName

#11274
From: schoene
Date: Sun, 22 Feb 2004 22:23
61 lines
2482 bytes
Hi,

I created a simple program to get the ComputerName. I execute the same code
in the constructor as in an OnClick-event of a button. This program works 
fine on my computer (WinXP). However, when I execute this program on a 
different computer, with Windows Me, everything works fine in the OnClick-
event, but when executing GetComputerName in the constructor, I get error 
87: The parameter is incorrect.

Does anyone know why this is?

regards,

Koen

//-------------------------------------------------------------------------
//the code:

//-------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
this->MyGetComputerName ();
}
//-------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->MyGetComputerName ();
}
//-------------------------------------------------------------------------
void __fastcall TForm1::MyGetComputerName ()
{
   unsigned long size;

   char name[MAX_COMPUTERNAME_LENGTH + 1] = {0};

   if (!GetComputerName (name, &size))
   {
      LPVOID lpMsgBuf;

      FormatMessage(
       FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
       NULL,
       GetLastError(),
       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
       (LPTSTR) &lpMsgBuf,
       0,
       NULL
      );

      // Display the string.
      MessageBox( NULL, (const char *) lpMsgBuf, "GetLastError", 
MB_OK|MB_ICONINFORMATION );

      // Free the buffer.
      LocalFree( lpMsgBuf );
   }
else
   Edit1->Text = AnsiString (name, size).LowerCase ();
}
//-------------------------------------------------------------------------
Technical Details
Message-ID: <40392bec$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,ac942ffac7941132,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-22 14:39:42 PST
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Problem with GetComputerName
From: schoene <email@email.com>
Organization: Your Company
User-Agent: Xnews/5.04.25
NNTP-Posting-Host: 81.164.226.52
Message-ID: <40392bec$1@newsgroups.borland.com>
Date: 22 Feb 2004 14:23:40 -0800
X-Trace: newsgroups.borland.com 1077488620 81.164.226.52 (22 Feb 2004 14:23:40 -0800)
Lines: 61
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail