what is the preferred method to pass a string between C++ and C#?
i have a c++ class where one of the functions takes a const char var1 and const char var2[]
as parameter.
When I call such function in C# , function accepts arguments types as sbyte*. Just using a c#-string doesnt seem to work as the function in C# requires a sbyte* and sbyte**
C++ class:
public ref class MyClass
{
public:
void Sample(const char * var1,const char* Var2[]);
}
C# call...
class Program
{
static void Main(string[] args)
{
MyClass oClass = new MyClass();
string var1 = "Variable1";
string[] var2 = {"1","2"};
oClass.Sample(var1,var2);
}
}
Error: Error 1 Argument 1: cannot convert from 'string' to 'sbyte*' Error 2 Argument 2: cannot convert from 'string[]' to 'sbyte**'
So I need help in understanding how can I pass string arguments from managed C# to managed C++?