🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.delphi.misc
Article #45

C++/Delphi sockets question

#45
From: Dave Prentice
Date: Mon, 29 Jun 1998 00:00
49 lines
2181 bytes
OK in Delphi I can use the winsock API send() function like this:

type
    TMyThing=record
        AMember: array[0..100] of char;
        ANOther: integer;
        YetANOther: TMyOtherThing;
end;

procedure Form1.Button1Click(Sender: TObject);
var
    thing: TMyThing;
begin
    {populate thing here}
    .
    .
    if send(asocket,thing, sizeof(TMyThing,0)<>sizeof(TMyThing) then
    {do some error handling}
end;

this seems to be because the winsock.pas header file describes send()
as:

function send(s: TSocket; var Buf; len, flags: Integer): Integer;
stdcall;

where the send buffer is a var pointer type.

unfortunately in C++ Builder, winsock.h declares send() as:

int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int
flags);

note the use of const char FAR * as the type for the send buffer. When I
create a similar TMyType in C++ I cant send it down my socket without
converting to some sort of char* - which I can't work out how to do !!
(I did notice that the TCustomWinSocket has a method:
int __fastcall ReceiveBuf(void *Buf, int Count);
which is looks what I want to do to my raw socket, however I want to
port the code over to UNIX at some point and guess I can't use this).

any comments/suggestions on this issue would be gratefully recieved here
or at
david.prentice@stocktrade.co.uk

Regards,

Dave Prentice
Technical Details
Message-ID: <3597BA2D.F6DFE3DB@stocktrade.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10baee,30838b54da12b6ba,start
X-Google-Attributes: gid10baee,public
X-Google-Thread: 10fbec,30838b54da12b6ba,start
X-Google-Attributes: gid10fbec,public
X-Google-Thread: f5ca7,30838b54da12b6ba,start
X-Google-Attributes: gidf5ca7,public
X-Google-Thread: f973d,30838b54da12b6ba,start
X-Google-Attributes: gidf973d,public
From: Dave Prentice <david.prentice@stocktrade.co.uk>
Subject: C++/Delphi sockets question
Date: 1998/06/29
Message-ID: <3597BA2D.F6DFE3DB@stocktrade.co.uk>
X-Deja-AN: 367127307
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: comp.lang.pascal.delphi.misc,alt.lang.delphi,borland.public.cppbuilder.winapi,borland.public.cppbuilder.ide