I have a C ++ - CLR wrapper around a standard C ++ library called from C #. To receive status messages from the library, I use the delegate assigned to the callback in C ++ code through Marshal :: GetFunctionPointerForDelegate.
It took me quite a while to work, and I'm very, very close (I think). A C # delegate is called, but the string is not passed correctly across the border.
When I call TakesCallback ("Test String") from C ++ code, I just return the garbage to the C # function.
--- C ++ source class and callback function ---
class Solver { private: std::string TakesCallback(const std::string message) { return cb(message); } public:
--- Function to set callback from managed wrapper ----
--- C # function passed to the C ++ \ CLR shell SetMessageCallBack ----
private void Message(string message) { XtraMessageBox.Show(message, "Done", MessageBoxButtons.OK); }
source share