🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4720

Acquiring PC's in a workgroup

#4720
From: Luke
Date: Thu, 06 Jan 2005 13:45
47 lines
2985 bytes
Just recently I have begun developing Winsock applications.  If I know the IP address of the computer I am connecting to every thing works fine.  The application I am developing sends messages to another computer (an instant messenger). 
I would prefer to have the user select which computer he would like to attempt to send the information to.  Just recently I have found code that determines the network configuration of the computer that is connected.  This is not supported in Win98 however.  
If someone would look over the following code, which does exactly what I need it to do, and provide replice using Win98 safe functions I would highly appreciate it.
Thanks - Luke 

void __fastcall TForm1::EnumFunc (LPNETRESOURCE lpnr)
{
  DWORD dwResult, dwResultEnum;
  HANDLE hEnum;
  DWORD cbBuffer = 16384;
  DWORD cEntries = 0xFFFFFFFF;
  LPNETRESOURCE lpnrLocal;
  DWORD i;

  dwResult = WNetOpenEnum (RESOURCE_CONTEXT, RESOURCETYPE_DISK, 0, lpnr, &hEnum);

  if (dwResult != NO_ERROR) {
      return;
  }

  lpnrLocal = (LPNETRESOURCE) GlobalAlloc (GPTR, cbBuffer);
  dwResultEnum = WNetEnumResource (hEnum, &cEntries, lpnrLocal, &cbBuffer);
  if (dwResultEnum == NO_ERROR)
  {
      for(i=0; i<cEntries; i++)
      {
          if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER))
          {
            if(ListBox1->Items->Count >= 0) ListBox1->Items->Add (lpnrLocal[i].lpRemoteName);
            AnsiString Ans1 = ListBox1->Items->Strings[ListBox1->Items->Count - 1];
            int pos = Ans1.Pos ("\\\\");
            if (pos) Ans1.Delete (1, pos+1);
            ListBox1->Items->Strings[ListBox1->Items->Count - 1] = Ans1;
            if(Ans1.Length() == 0) ListBox1->Items->Delete(ListBox1->Items->Count - 1);
          }
      }
  }
  else if (dwResultEnum != ERROR_NO_MORE_ITEMS) return;

  HOSTENT *host;
  host = gethostbyname("LUKEMAIN");
  Label6->Caption = AnsiString(inet_ntoa(*(reinterpret_cast<in_addr*>(host->h_addr_list[0]))));

  GlobalFree((HGLOBAL) lpnrLocal);
  dwResult = WNetCloseEnum(hEnum);
} 
Technical Details
Message-ID: <41dd4104$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,cb0199ef5a630989,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Luke" <crazylukedog@yahoo.com>
Sender: "Luke" <crazylukedog@yahoo.com>
Reply-To: "Luke" <crazylukedog@yahoo.com>
Subject: Acquiring PC's in a workgroup
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 67.161.139.207     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41dd4104$1@newsgroups.borland.com>
Date: 6 Jan 2005 05:45:40 -0800
X-Trace: newsgroups.borland.com 1105019140 207.105.83.66 (6 Jan 2005 05:45:40 -0800)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail