0

I am working on a task where UI is written in c# (WPF). And there is some other module which is implemented in native c++. I need to register callback from c++ module to c# module by which i can get updated value of any variable (like string type). For example : In c ++ :

String str =" ";

If there is any change done by c++ module on str like str= " and"; Then i need to send this updated value to c# module.

Please suggest me how i can do this?
P.S.: C# and c++ module are in different dll. If any thing need to change in dll property that is also ok for me.

Thanks in advance.

1 Answers1

0

I always solved this by using a COM interface declared in C# and implemented in either C# (when you need to handle the callback from C++ to C#) and in C++ when is the other way around. You will have to declare in C# and interface that is COM visible

   [ComVisible(true)]
   [GuidAttribute("12347261-8AF6-45ae-BAFD-6DFF7A8798E4")]
   [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
   public interface ICOMInterface
   { *** }

and after that implement the interface in C++ based on a .tlb, .tlh

  • Thanks for quick response. I have checked question (due to that it is marked as duplicate ) but i am not able to run that in visual studio. Can some please provide the code for same, so that i can debug and run in visual studio? – user8832205 Aug 13 '19 at 13:53