locked
How do I call C# code from C++ code RRS feed

  • Question

  • Hi,

    I know this question has been asked before, but I'm a little confused how to handle this situation.

    I have a C# exe that contains a class that stores a dictionary of name/value pairs.

    I also have a C++ (COM) DLL that gets loaded by my C# exe.

    I need the C++ code to be able to set/get the name/value pairs stored in the C# code.

    I am thinking I need to create a C# wrapper class that is yet another COM object that the C++ code can call, but I feel like things could get a little convoluted with COM object1 calling COM object2 which in turn calls the C# code.

    Is this really the best approach?

    Thanks,
    Jason

    • Moved by Bob Shen Friday, March 29, 2013 5:21 AM
    Thursday, March 28, 2013 2:36 AM

Answers

  • No need for another wrapper. Since you are already using COM interop, In the COM server, declare a PairRequired event and Pair lookup/add/remove methods. Subscribe the event in C# and call the methods to change the pairs stored in the COM server.


    Visual C++ MVP

    • Marked as answer by Mike Feng Wednesday, April 3, 2013 5:10 PM
    Friday, March 29, 2013 2:04 PM

All replies

  • Hi nosage,

    I would like to redirect you to appropriate forum for better responses.  


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 29, 2013 5:20 AM
  • No need for another wrapper. Since you are already using COM interop, In the COM server, declare a PairRequired event and Pair lookup/add/remove methods. Subscribe the event in C# and call the methods to change the pairs stored in the COM server.


    Visual C++ MVP

    • Marked as answer by Mike Feng Wednesday, April 3, 2013 5:10 PM
    Friday, March 29, 2013 2:04 PM