Article View: borland.public.cppbuilder.nativeapi
Article #15927Re: Thread synchronize
From: Remy Lebeau (TeamB)
Date: Sun, 08 Jun 2003 20:35
Date: Sun, 08 Jun 2003 20:35
63 lines
2531 bytes
2531 bytes
"Tharun Pillay" <tharun@webmail.co.za> wrote in message
news:3ee3378b@newsgroups.borland.com...
> Does anyone know how to implement the VCL
> TThread->Synchronize using APIs?
> My problem is I need to call a function in the
> VCL thread to create a TClientSocket and send it
> back to my worker thread somehow.
Up to and including BCB5, Synchronize() is implementated using SendMessage()
to send a custom message to the main VCL thread, where the lParam of the
message is a pointer to the thread that is calling Synchronize(). You could
do something similar to let the main VCL thread return a pointer back to
your thread, ie:
typedef struct
{
TMyThread *thread;
TClientSocket *socket;
} TMyStruct;
#define APPWM_MYMESSAGE (WM_APP + 100)
...
void __fastcall TMyThread::Execute()
{
...
TMyStruct s;
s.thread = this;
s.socket = NULL;
if( SendMessage(Application->MainForm->Handle, APPWM_MYMESSAGE, 0,
(LPARAM)&s) )
{
// use s.socket as needed
delete s.socket;
}
...
}
...
void __fastcall TMainForm::WndProc(TMessage &Message)
{
if( Message.Msg == APPWM_MYMESSAGE )
{
try
{
((TMyStruct*)Message.LParam)->socket = new
TClientSocket(NULL);
Message.Result = TRUE;
}
catch(Exception&) {
Message.Result = TRUE;
}
}
else
TForm::WndProc(Message);
}
Gambit
Technical Details
Message-ID:
<3ee39d3f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ee3378b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,82b0c0f74a86ff1b X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-08 13:42:19 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ee3378b@newsgroups.borland.com> Subject: Re: Thread synchronize Date: Sun, 8 Jun 2003 13:35:17 -0700 Lines: 65 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3ee39d3f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1055104319 207.175.226.26 (8 Jun 2003 13:31:59 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail