I have some of unmanaged C++ dynamic library and C# GUI application, using it. I need to pass array of strings with known size to C++ library, which populates it. Also there is maximum string length value:
// C++ part
#define MAX_SOME_STRING_LEN 250;
MYDLL_API uint8_t __stdcall getSomeStrings(wchar_t** strings, uint64_t count) {
/// populate strings, not more characters then MAX_SOME_STRING_LEN for each string
return 0;
}
// C# part
[DllImport("biosec_lib.dll", CallingConvention = CallingConvention.StdCall)]
static extern Byte getSomeStrings(string[] providers, UInt64 size);
I want to avoid array memory management on C++ library side. I get desirable string array size by other library API call. Then allocate suitable array on C# side and call this API method, passing suitable array.
- Is it good approach at all? Is there any better approach? Can I reserve MAX_SOME_STRING_LEN size for every string in my array before passing it to API method?