🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7939

For those who have struggled with callback

#7939
From: Angus
Date: Thu, 09 Dec 2004 04:34
43 lines
2402 bytes
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: <41b7d5c0@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8db932b21c7928ca,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Angus" <anguspickton@yahoo.com>
From: "Angus" <aguspickton@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: For those who have struggled with callback
Date: Thu, 9 Dec 2004 17:34:18 +1300
Lines: 45
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 219.88.83.204
Message-ID: <41b7d5c0@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102566848 219.88.83.204 (8 Dec 2004 20:34:08 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail