Click here to Skip to main content
15,881,812 members
Home / Discussions / C#
   

C#

 
QuestionDelegates - I don't Get It Pin
eddieangel17-Jul-09 7:52
eddieangel17-Jul-09 7:52 
AnswerRe: Delegates - I don't Get It Pin
harold aptroot17-Jul-09 8:14
harold aptroot17-Jul-09 8:14 
AnswerRe: Delegates - I don't Get It Pin
CodingYoshi17-Jul-09 8:20
CodingYoshi17-Jul-09 8:20 
GeneralRe: Delegates - I don't Get It Pin
eddieangel17-Jul-09 8:35
eddieangel17-Jul-09 8:35 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 10:47
professionalDaveyM6917-Jul-09 10:47 
GeneralRe: Delegates - I don't Get It Pin
eddieangel17-Jul-09 11:00
eddieangel17-Jul-09 11:00 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 11:26
professionalDaveyM6917-Jul-09 11:26 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 11:39
professionalDaveyM6917-Jul-09 11:39 
Here's a simplified version of what I posted above. This is not real world, but could be if there were no return values or parameters involved! This will be easier to follow I hope!
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    delegate void MyDelegate();

    public partial class Form1 : Form
    {
        public event EventHandler FunctionCalled;

        MyDelegate myDelegate;
        public Form1()
        {
            InitializeComponent();
            myDelegate = FunctionCallback;
        }

        public void CallNativeFunction()
        {
            function(myDelegate);
        }

        void FunctionCallback()
        {
            OnFunctionCalled(EventArgs.Empty);
        }

        protected virtual void OnFunctionCalled(EventArgs e)
        {
            EventHandler eh = FunctionCalled;
            if (eh != null)
                eh(this, e);
        }

        [DllImport("your.dll")]
        static extern void function(MyDelegate callback);
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)

AnswerRe: Delegates - I don't Get It Pin
Luc Pattyn17-Jul-09 10:13
sitebuilderLuc Pattyn17-Jul-09 10:13 
GeneralRe: Delegates - I don't Get It Pin
Baeltazor17-Jul-09 22:28
Baeltazor17-Jul-09 22:28 
QuestionCrystalReports Pin
CodingYoshi17-Jul-09 7:06
CodingYoshi17-Jul-09 7:06 
AnswerRe: CrystalReports Pin
Adam R Harris17-Jul-09 9:20
Adam R Harris17-Jul-09 9:20 
GeneralRe: CrystalReports Pin
Adam R Harris17-Jul-09 10:41
Adam R Harris17-Jul-09 10:41 
GeneralRe: CrystalReports Pin
CodingYoshi17-Jul-09 10:54
CodingYoshi17-Jul-09 10:54 
QuestionCommon components in C# and .net? Pin
saxisa17-Jul-09 7:01
saxisa17-Jul-09 7:01 
QuestionNTLM Authentication in C# Pin
joana.simoes17-Jul-09 5:39
joana.simoes17-Jul-09 5:39 
AnswerRe: NTLM Authentication in C# Pin
Adam R Harris17-Jul-09 9:25
Adam R Harris17-Jul-09 9:25 
GeneralRe: NTLM Authentication in C# Pin
joana.simoes19-Jul-09 23:34
joana.simoes19-Jul-09 23:34 
GeneralRe: NTLM Authentication in C# Pin
joana.simoes19-Jul-09 23:50
joana.simoes19-Jul-09 23:50 
AnswerRe: NTLM Authentication in C# Pin
joana.simoes20-Jul-09 3:30
joana.simoes20-Jul-09 3:30 
QuestionRichTextBox- :(( Pin
RongNK17-Jul-09 4:49
RongNK17-Jul-09 4:49 
AnswerRe: RichTextBox- :(( Pin
Manas Bhardwaj17-Jul-09 4:59
professionalManas Bhardwaj17-Jul-09 4:59 
GeneralRe: RichTextBox- :(( Pin
RongNK17-Jul-09 5:04
RongNK17-Jul-09 5:04 
GeneralRe: RichTextBox- :(( Pin
Manas Bhardwaj17-Jul-09 5:14
professionalManas Bhardwaj17-Jul-09 5:14 
GeneralRe: RichTextBox- :(( Pin
RongNK17-Jul-09 5:39
RongNK17-Jul-09 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.