New Message on dotNET User Group Hyd

VJs Tip Of The Day

Reply
  Reply to Sender   Recommend Message 44 in Discussion
From: VishalRJoshi

Callback functions

Callback functions are powerful tools and we should know how to use them...
In general a callback function is a reference to a method that you pass to
another method... When the second method calls the referenced method , it
actually calls back to the first method... This might be a confusing
terminology but a code snippet from MSDN will probably help make it
clearer...

using System;
using System.Runtime.InteropServices;

public delegate bool CallBack(int hwnd, int lParam);

public class EnumReportApp {

[DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y);

public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
}

public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}

Here is the link for you to explore more....
http://msdn.microsoft.com/library/default.asp?url="">l/cpconusingcallbackfunctions.asp

PS: I have coined a new term called "Developer's Superstition"... I suffer
from this problem often - When code does not seem to behave the way I want
it to, knowingly/unknowingly I try things which I know will not work, which
I know are technically impossible but still I do just to make myself feel
good that I have left no stones unturned... I wonder whether you guys also
do such thing... A classic example would be trying to call GC.Collect()
method when a StreamReader is not releazing a file even after calling
close()...{usually its some other process holding the reference...:-)} I
wonder has MS Technologies made me superstitious or is this same
everywhere... :-)

Vishal Joshi
Microsoft MVP .Net
If You Think YOU CAN... You Can...
http://VishalJoshi.Blogspot.com
http://www.microsoft.com/india/mvp/indiamvp.aspx
http://groups.msncom/ChennaiNetUserGroup
http://groups.msn.com/CNUG-DAM
http://groups.msn.com/NetBloomingtonUserGroup


View other groups in this category.

Click Here!
Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to