Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass a string from managed C# to managed C++

Tags:

c++

string

c#

.net

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 char const * const as parameter.

how would i call this function in C#? just using a c#-string doesnt seem to work as the function in C# requires a sbyte*

C++ class:

public ref class MyClass
{
public:
    void Sample(char const * const Name);
}

Error 2 Argument '1': cannot convert from 'string' to 'sbyte*'

thanks!

like image 997
clamp Avatar asked Aug 17 '26 16:08

clamp


1 Answers

If you are using managed C++, you can use System.String class

like image 63
denisenkom Avatar answered Aug 19 '26 06:08

denisenkom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!