I am wrapping some native C++ code in a C++/CLI .dll for use in .NET projects - mainly C#. The number of calls will be large so I am looking to do this in an effective way. The function I am wrapping takes the following arguments:
int SomeFun(
const char* input_text,
int* output_array,
bool* output_value);
I know how to do an efficient System::String
to const char*
cast thanks to this answer. My questions are these:
- The function expects pointers to
output_array
andoutput_value
which need to be created/cleaned-up and returned to the managed component all inside the wrapper. How do I do that? - How do I return multiple values to the managed environment from the wrapper .dll - by using a struct as a return value?
- For now I am trying to do all the pointer handling and managed/unmanaged interaction inside the wrapper .dll but this article (Solution 3) suggests that using an "unsafe" environment inside C# is the fastest. Is this likely to be a better option for what I am trying to do? I guess it would make the wrapper less complex but also require more elaborate treatment in C#.
Thanks,
/David