I know that I can achieve this in order to technically work, but I would like to implement the cleanest possible solution. Here's the situation:
I have a managed library that wraps an unmanaged C-style library. The C-style library library that I am currently processing is doing some processing, including a list of strings. The client code of the library can be provided by the delegate, so that during the processing of the list, if an "invalid" script is encountered, the library can contact the client through this delegate and allow them to choose the strategy used (throw an exception, replace invalid characters, etc.)
Ideally, I would like all managed C ++ to be isolated in one function, and then able to call a separate function that accepts only unmanaged parameters, so that all native C ++ and unmanaged code are isolated at the same time. Providing a callback mechanism to this unmanaged code turns out to be a braking point for me.
#pragma managed public delegate string InvalidStringFilter(int lineNumber, string text); ... public IList<Result> DoListProcessing(IList<string> listToProcess, InvalidStringFilter filter) { // Managed code goes here, translate parameters etc. } #pragma unmanaged // This should be the only function that actually touches the C-library directly std::vector<NativeResult> ProcessList(std::vector<char*> list, ?? callback);
In this snippet, I want to keep all access to the C-library in ProcessList, but during processing it will need to make callbacks, and this callback is provided as an InvalidStringFilter delegate, which is transferred from some client of my managed library.
source share