Click here to Skip to main content
15,919,434 members
Home / Discussions / C#
   

C#

 
GeneralRe: TcpClient - Detecting closed connections Pin
BobJanova11-Oct-11 3:20
BobJanova11-Oct-11 3:20 
AnswerRe: TcpClient - Detecting closed connections Pin
jschell11-Oct-11 9:21
jschell11-Oct-11 9:21 
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes11-Oct-11 19:21
Grimes11-Oct-11 19:21 
QuestionCompare 2 Datatables Pin
jojoba2010-Oct-11 6:13
jojoba2010-Oct-11 6:13 
AnswerRe: Compare 2 Datatables Pin
André Kraak10-Oct-11 8:27
André Kraak10-Oct-11 8:27 
GeneralRe: Compare 2 Datatables Pin
jojoba2010-Oct-11 8:30
jojoba2010-Oct-11 8:30 
GeneralRe: Compare 2 Datatables Pin
André Kraak10-Oct-11 9:30
André Kraak10-Oct-11 9:30 
QuestionFire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils10-Oct-11 4:27
Tonkpils10-Oct-11 4:27 
Hi,

I need some help for solving the following problem.
I got an event in C# an registered some methods to the event. I can fire them by calling the event with MyEvent().
C#
//C# events
eventDo += TestFkt; //registering
eventDo();          //testcall

It works fine.

The problem is the 'outsourcing' of the eventcall.
I want to register the methods to an event in C# but the event is fired within a C++ DLL with the command
C++
//C++ event-call
SetEvent(HANDLE hEvent) 


I can pass the hEvent via a DLL-call to the C++ code:
C#
//C# DLL-call
[DllImport("canapi2.dll", EntryPoint="CAN_SetClientParam")]
public static extern uint SetClientParam(
            ushort wParam,
            int   dwValue);

The Method in the C++-Code to set the HANDLE hEvent
C++
CAN_SetClientParam(
        WORD        wParam,   //specifies kind of parameter
        DWORD       dwValue); //Event handle

In the C++-Code of the CAN-driver
C#
SetEvent((HANDLE) dwValue) 

is called while receiving CAN-Messages. With this call I want to inform the C#-Application.

Get anyone an idea, how to - let's say 'extract' - the Handle from the C#-event and pass it through the DLL?

Following code snippet doesn't work:
C#
IntPtr iptr = Marshal.GetFunctionPointerForDelegate(eventDo);
SetClientParam(PARAM_ONRCV_EVENT_HANDLE, (int)(iptr));




Thanks for answering!
AnswerRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
DaveyM6910-Oct-11 7:09
professionalDaveyM6910-Oct-11 7:09 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils13-Oct-11 4:37
Tonkpils13-Oct-11 4:37 
AnswerRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
TheGreatAndPowerfulOz10-Oct-11 12:13
TheGreatAndPowerfulOz10-Oct-11 12:13 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils11-Oct-11 1:01
Tonkpils11-Oct-11 1:01 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
TheGreatAndPowerfulOz14-Oct-11 4:51
TheGreatAndPowerfulOz14-Oct-11 4:51 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils18-Oct-11 0:17
Tonkpils18-Oct-11 0:17 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
TheGreatAndPowerfulOz18-Oct-11 8:23
TheGreatAndPowerfulOz18-Oct-11 8:23 
QuestionHow to highlight all occurrences of a word in a Word document?? Pin
fiaolle10-Oct-11 4:20
fiaolle10-Oct-11 4:20 
AnswerRe: How to highlight all occurrences of a word in a Word document?? Pin
Pete O'Hanlon10-Oct-11 4:52
mvePete O'Hanlon10-Oct-11 4:52 
GeneralRe: How to highlight all occurrences of a word in a Word document?? Pin
fiaolle10-Oct-11 5:08
fiaolle10-Oct-11 5:08 
GeneralRe: How to highlight all occurrences of a word in a Word document?? Pin
Pete O'Hanlon10-Oct-11 5:19
mvePete O'Hanlon10-Oct-11 5:19 
GeneralRe: How to highlight all occurrences of a word in a Word document?? Pin
fiaolle10-Oct-11 6:25
fiaolle10-Oct-11 6:25 
GeneralRe: How to highlight all occurrences of a word in a Word document?? Pin
Shameel11-Oct-11 0:32
professionalShameel11-Oct-11 0:32 
AnswerRe: How to highlight all occurrences of a word in a Word document?? Pin
jschell10-Oct-11 8:08
jschell10-Oct-11 8:08 
GeneralRe: How to highlight all occurrences of a word in a Word document?? Pin
fiaolle10-Oct-11 9:07
fiaolle10-Oct-11 9:07 
QuestionIs there a way to run nunit Test class 50 times in a loop ? Pin
Subin Mavunkal10-Oct-11 0:59
Subin Mavunkal10-Oct-11 0:59 
AnswerRe: Is there a way to run nunit Test class 50 times in a loop ? Pin
Pete O'Hanlon10-Oct-11 1:14
mvePete O'Hanlon10-Oct-11 1: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.