Article View: borland.public.cppbuilder.nativeapi
Article #7940Re: For those who have struggled with callback
From: Brent
Date: Thu, 09 Dec 2004 04:41
Date: Thu, 09 Dec 2004 04:41
55 lines
2936 bytes
2936 bytes
Great that you worked it out. Here's a link to an article that discusses
callback functions with C++, API and VCL events.
http://bcbjournal.org/articles/vol4/0007/Understanding_function_pointers.htm
"Angus" <aguspickton@yahoo.com> wrote in message
news:41b7d5c0@newsgroups.borland.com...
> No matter how many times i read about callback functions, i could never
> really grasp them. It often depends on the information is presented. With
> respect to callbacks, a little light flickered on, and here is an
> explanation for anyone dense as hardwood like myself. - and if you don't
> like it, oh well.
>
> Callback - the passing of your own function as a parameter into another
> function. Consider the call.
>
> void __fastcall TForm1::Button1Click(TObject *Sender){
> std::auto_ptr<TComboBox>CB(new TComboBox(this));
> SomeFunction( MyFunc, CB);
> }
>
> Now SomeFunction may be something you have written to retrieve a list of
all
> say all process names.. ie.
>
> BOOL WINAPI SomeFunction(PROCENUMPROC myfunc, LPARAM lParam){
> // ...some code..e.g getting a the next process in a snapshot list.
now
> call your own function MyFunc.e.g.
>
> while(MyFunc(processname, lParam) && ProcessesRemain){
> //pass in a var from this func, AND a var from your calling vcl
> program
> if(dada)
> ProcessesRemain = false;
> }
> }
>
> ...and MyFunc...
> BOOL CALLBACK MyFunc(char* processname, LPARAM lParam){
> TComboBox* cb = (TComboBox*)lParam; //do a cast
> cb->Items->Add(AnsiString(processname));
> return true;
> }
>
> In essence then, MyFunc is passed into SomeAPICallbackFunction. In this
> example, each process is iterated using snapshot.
> With each process found, a call to MyFunc is made, passing in the name of
> the process.. and in this instance a link to your calling program, a combo
> box.
>
> rgds Angus.
>
>
Technical Details
Message-ID:
<41b7d761@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!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-mailReferences:
<41b7d5c0@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8db932b21c7928ca X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Brent" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41b7d5c0@newsgroups.borland.com> Subject: Re: For those who have struggled with callback Date: Thu, 9 Dec 2004 15:41:04 +1100 Lines: 57 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 203.10.46.175 Message-ID: <41b7d761@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1102567265 203.10.46.175 (8 Dec 2004 20:41:05 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!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