0

I need to implement an event mechanism similar to C# in C++.

  1. C++ Class will raise an event
  2. CLI Class will subscribe the C++ class event
  3. Then CLI class will raise another event
  4. C# class will subscribe the CLI event

This is the logic I am looking for. Is there any mechanism to achieve this?

I tried by passing Function pointers.But its not working as expected

Hari Sankar v m
  • 163
  • 1
  • 12
  • What do you mean with `CLI will catch the event` and raise it to C#? Is the C# application launched in an other thread? Is the CLI code cross-compiled? – user3520616 Nov 21 '19 at 06:55
  • C# will be an exe. CLI and C++ will be like dlls. I want to notify C# if something happened in C++ – Hari Sankar v m Nov 21 '19 at 08:50
  • A .dll doesn't do anything from itself, therefore your question doesn't really make sense. You have to be clear on what you are trying to achieve. – user3520616 Nov 21 '19 at 09:04
  • Lots of existing questions, like [this one](https://stackoverflow.com/questions/2972452/c-cli-pass-managed-delegate-to-unmanaged-code) – Hans Passant Nov 21 '19 at 10:36

2 Answers2

0

In general, I would say: yes. By using C++/CLI you can implement wrapper around your native (C++) object that rises an event. Next, you can catch this event and produce managed (.Net) event in your C++/CLI wrapper. Finally, this managed event can be handled in your C# app. Here you have an example.

0

You Can Implement as Below.

  1. Pass a function pointer to C++ from CLI. so that by calling the function pointer from C++, CLI function will be executed.

  2. From CLI to C#, you can use normal C# event which is available for CLI.