Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 415
  • Last Modified:

CallBack in Windows

Can anybody explain how call backs work in Windows Programming? Since I am new, a good example would be very helpful.
What I am trying to do is I have total three processes running:
Application one has a thread running continuously and getting events from a second application.
When the thread receives certain events I want my third application to know about those events.

I think I can setup callback functions, so the thread will notify the third application using callback.
0
Nutty104
Asked:
Nutty104
1 Solution
 
jhanceCommented:
VC++ is a compiler from Microsoft.  CALLBACK is a function type modifier for specifying a function that can be "called back" by another function in Windows.

The two are unrelated concepts.

What is it you are trying to do?  Ask a better question and you'll get a better answer....
0
 
djbusychildCommented:
callbacks are function that get called when something happens.

I think you mean "windows programming" when you say "Visual C++"....

for example, when you register your window you have to fill in a WNDCLASS structure

http://msdn.microsoft.com/library/psdk/winui/winclass_8yk2.htm

one of the field in the structure is lpfnWndProc.
you set this to point a function and whenever your window gets a message that function gets called... that's the basic idea.
0
 
djbusychildCommented:
play around with the wizard to create a win32 hello world application from Visual C++. You'll find functions that
fill in the WNDCLASS structure and also the function that gets called when your window receives a message.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GloriousRainCommented:
A callback function is essentially an event handler that is implemented by an application and called by the system. Microsoft? Windows? applications typically implement multiple callback functions, each one designed for a particular set of events. When an event occurs, the system notifies the application by calling the appropriate callback function. The callback function also usually has a parameter list that the system can use to pass the application more detailed information about the event. The most common example of a callback function is the window procedure. This function is used by the system to pass Windows messages to the applications that owns the window.
Example:
typedef void (__cdecl *lpCallback)();

void _cdecl CallBack();
void Function(lpCallback);
void Test_Func();

void _cdecl CallBack()
{
}

void Function(lpCallback)
{
}

void Test_Func()
{
     Function(CallBack);
}
0
 
ambienceCommented:
Application one has a thread running continuously and getting events from a second application.

>>> How is that application getting events ? are you using connection points for this ?

When the thread receives certain events I want my third application to know about those events.

>>> Sure you can do this

I think I can setup callback functions, so the thread will notify the third application using callback.

>>> Callbacks require you to pass address of a function to the server which the srver saves and the srever later calls the function thru that pointer when required and this way notifies the client of something .. this is the jist of call backs.. note that in Win32 a pointer to some function in one process is meaningless to the other one and atleast is invalid (due to private address space) so you cannot directly call a function in some other process from another process.

Using callbacks maynot be the best approach in your case , if you can get away by using windows messages that is a good way out.

Incase you are alerady using connection points for communication between App1 and App2 , why not do the same for App2 and App3 (ofcouse if you are willing to make App2 a COM server :)) .


0
 
djbusychildCommented:
whoa... how did we move onto COM all of a sudden? ^^

there's really no reason to make matters complicated just to do some simple IPC.

Nutty, look into the following sections of the MSDN.

http://msdn.microsoft.com/library/psdk/winbase/ipc_57qr.htm
0
 
ua1zclCommented:

Nutty, for simplicity you can make 3 applications
Hello World. Assign wcl.lpszClassName with different
names. Then use FindWindow to get window handle
 and PostMessage function to post a message.

in message loop of window proc:

// add to app2 "App2class")
case WM_LBUTTONDOWN:
  {HWND hw=FindWindow("App1class",0);
    if(hw)PostMessage(hw,WM_COMMAND,IDYES,0);//to app1
  }
  break;
 
// add to app1 ("App1class")
  case WM_COMMAND:
  switch (LOWORD(wParam))
  {
    case IDYES:
    {
     HWND hw=FindWindow("App3class",0);
     if(hw)PostMessage(hw,WM_COMMAND,IDYES,0);//to app
    }
    break;

// add to app3 ( "App3class")
  case WM_COMMAND:
  switch (LOWORD(wParam))
  {
    case IDYES:
     MessageBox(0,"Message received ","App3",MB_OK);
     
    break;

There in Windows is many other possibilities to
communicate , this is very simple example.



0
 
Nutty104Author Commented:
Hi All,

Thanx for all your help and comments. ua1zcl and ambience have provided quite a good explanation of my question. So I would like to split the points btwn them.

Thanx all.......
0
 
Nutty104Author Commented:
How do u split points?

It seems like all the points are given to ua1zcl.....

0
 
AxterCommented:
How do u split points?
Reequest that the points be split in the Community Support topic area.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now