🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

BDS2006 requires WSAStartup be called...

#2285
From: Mark Jacobs
Date: Tue, 06 Jun 2006 10:36
73 lines
3294 bytes
The following works correctly under BCB5. Virgin BCB2006 VCL project, drop a 
button onto the form :-

//--HEADER FILE------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <WSockets.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
   TButton *Button1;
   void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public:  // User declarations
   __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

//--SOURCE FILE------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
 : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  struct hostent *mhstj; struct in_addr mjinad;
  unsigned long eha; int ii=0; AnsiString cret;
  mhstj=gethostbyname("");
  if (!mhstj)
  {
    ShowMessage("Socket Error "+AnsiString(WSAGetLastError()));
    return;
  }
  cret=AnsiString(mhstj->h_name);
  while (mhstj->h_addr_list[ii])
  {
    memcpy(&mjinad,mhstj->h_addr_list[ii++],sizeof(in_addr));
    cret+="\n"+AnsiString(inet_ntoa(mjinad));
  }
  ShowMessage("Hello  - Your IP Details are :-\n"+cret);
}
//---------------------------------------------------------------------------

In BCB5 I get the IP details as expected. In BDS2006 error 10093 is returned 
implying something about WSAStartup not being called. Having looked at the 
structure required to set up a call to WSAStartup, I am not happy. Why doesn't 
this work as is?
-- 
�
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
Technical Details
Message-ID: <44855a92$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,ef067702696d334e,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII
From: "Mark Jacobs" <http://www.jacobsm.com/mjmsg?Borland%20Newsgroup>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: BDS2006 requires WSAStartup be called...
Date: Tue, 6 Jun 2006 11:36:19 +0100
Lines: 75
Organization: DK Computing
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 81.144.157.8
Message-ID: <44855a92$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149590162 81.144.157.8 (6 Jun 2006 03:36:02 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.google.com!news2.volia.net!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail