none
Need a good sample code where I can call a callback function from c# dll into a c++ code. RRS feed

  • Question

  • I have a c# dll witch receives makes calculation and generates results, when this is done, I like to invoke a callback function into c++ exe. Thanks

    Tuesday, July 3, 2018 2:41 PM

All replies

  • Normally you create a delegate from the function pointer and call that. How you get the delegate depends on where/how you get the function pointer. If you use a delegate type in the pinvoke or com method signature, then the marshaler will create the delegate from the function pointer for you, otherwise you will probably need to use Marshal.GetDelegateFromFunctionPointer(). In either case, you almost certainly won't be able to use Action<> or Func<> as the delegate type will need to be decorated in much the same way as a pinvoke method.
    Tuesday, July 3, 2018 9:58 PM
  • Hi basem1965,

    Thank you for posting here.

    For your question, please refer to the link below for reference about invoke callback function from C# to C++.

    https://inphamousdevelopment.wordpress.com/2012/10/01/sending-callbacks-from-c-to-c/

    https://stackoverflow.com/questions/6507705/callbacks-from-c-back-to-c-sharp

    Best Regards,

    Wendy

    Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet. 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 4, 2018 6:14 AM
    Moderator