Click here to Skip to main content
15,887,422 members
Home / Discussions / C#
   

C#

 
QuestionMS Word Automation - Combining word documents Pin
venadder17-Jul-09 11:25
venadder17-Jul-09 11:25 
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 
Without the API that you're using it's difficult to give you an example, but here's one I used recently for retrieving MIDI input messages. The function looks like this:
[DllImport("winmm.dll")]
public static extern UInt32 midiInOpen(
    out IntPtr lphMidiIn,
    UInt32 uDeviceID,
    MidiProc dwCallback,
    UInt32 dwCallbackInstance,
    UInt32 dwFlags);
The delegate looks like this:
internal delegate void MidiProc(
    IntPtr handle,
    UInt32 wMsg,
    UInt32 dwInstance,
    UInt32 dwParam1,
    UInt32 dwParam2);
The managed Open method that wraps the midiInOpen function in my MIDIInput class is:
public void Open()
{
    if (!IsOpen)
    {
        UInt32 result = Functions.midiInOpen(out handle, ID, midiProc, ID, Constants.CALLBACK_FUNCTION);
        if (result == Constants.MMSYSERR_NOERROR)
        {
            IsOpen = true;
            Manager.openInputs.Add((Input)this);
            OnOpened(EventArgs.Empty);
        }
        else
            throw new MIDIException(GetErrorText(result));
    }
}
This class has a field
internal MidiProc midiProc;
and in the constructor I assign the midiProc to the method.
midiProc = MessageHandler;
When the delegate (callback) is called, it now calls my MessageHandler method which raises the event(s).
protected override void MessageHandler(IntPtr handle, uint wMsg, uint dwInstance, uint dwParam1, uint dwParam2)
{
    switch (wMsg)
    {
        case Constants.MIM_DATA:
            OnDataReceived(new DataReceviedEventArgs(dwParam1, dwParam2));
            break;
        case Constants.MIM_ERROR:
            OnDataReceived(new DataReceviedEventArgs(dwParam1, dwParam2, true));
            break;
    }
}


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)

GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 11:39
professionalDaveyM6917-Jul-09 11:39 
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 

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.