Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ event callback converted to c# events

Posted on 2015-01-11
4
Medium Priority
?
363 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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

783 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