Solved

C++ event callback converted to c# events

Posted on 2015-01-11
4
282 Views
Last Modified: 2015-01-11
Hi Experts,

I have a C++ callback interface (bunch of pure virtual functions in a class).  The c++ library is being instantiated in a c# class library now.

So naturally, I want to convert these "events" as c# events now.

My thinking is to create delegates in the wrapper library and convert them directly, firing them off to c#.

I know that on the C# side, if these events come from a different thread, I need to invokeLater.

Is there anything I could have done differently to make my life better here?  Looking for any great ideas at all...  :-)

Thanks,
Mike
0
Comment
Question by:thready
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40543190
Maybe this article could indeed help to make things easier: http://www.codeproject.com/Tips/393817/Pass-Csharp-delegate-as-Callback-to-Cplusplus ("Pass C# Delegate as Callback to C++") - if you just pass the delegates to the C++ callback interface to be invoked from there, it should be a piece of cake.
0
 
LVL 1

Author Comment

by:thready
ID: 40543220
I've got a bigger problem.  I'm trying to do this in my CLR class library.  I don't have the ability to add any C# classes to this implementation.  How can I fire off events in here?  Is there some other type of class that I can use in this context?  I don't even see how to do this at the moment...

Mike
0
 
LVL 1

Author Closing Comment

by:thready
ID: 40543226
I just clicked... I export these functions as in your link above.  Sorry about that!  :-)
Awesome.
0
 
LVL 1

Author Comment

by:thready
ID: 40543234
Actually, this is for the exported DLL type of interop... I'm not sure this works for the CLR class library method...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question