Thread View: comp.lang.pascal.delphi.misc
2 messages
2 total messages
Started by Dave Prentice
Mon, 29 Jun 1998 00:00
C++/Delphi sockets question
Author: Dave Prentice
Date: Mon, 29 Jun 1998 00:00
Date: Mon, 29 Jun 1998 00:00
49 lines
2181 bytes
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
Re: C++/Delphi sockets question
Author: Fran๏ฟฝois Piette
Date: Tue, 30 Jun 1998 00:00
Date: Tue, 30 Jun 1998 00:00
56 lines
2645 bytes
2645 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
I suggest you use TWSOcket component from the freeware ICS package. You'll
get full source code and compatibility withh *ALL* Delphi and C++Builder
versions. And if you don't wants to use the component, you can see how it
works as full source code is provided. Download from
http://www.rtfm.be/fpiette/indexuk.htm
--
francois.piette@pophost.eunet.be
The freeware Internet Component Suite maker
Download from http://www.rtfm.be/fpiette/indexuk.htm
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads