I want to make a native C++ all that can be used from a C# project.
- If I want to pass a string from C# to the function in the C++ all, what parameter should I use?
- I know that C# strings use Unicode, so I tried wchar_t * for the function but it didn't work; I tried catching any exceptions raised from the called function, but no exception was thrown.
- I also want to return a string so I can test it.
The C++ function is the following:
DECLDIR wchar_t * setText(wchar_t * allText) {
return allText;
}
The C# code is the following:
[DllImport("firstDLL.Dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
public static extern string setText(string allText);
var allText= new string('c',4);
try {
var str1 = setText(allText);
}
catch (Exception ex) {
var str2 = ex.Message;
}
What type should I use for the C++ function's return type, so that I can call it from C# with a return type of string[]
?
the same Q but for the parameter of the function to be string[] in C#?