Tom Stickel
Tom Stickel

Reputation: 20401

C# string passed to C++ CLI

Not seeing what I was looking for on S/O. I have a C# app that needs to pass values to a C++ CLI application (managed code). (I REALLY ONLY NEED TO FIGURE OUT STRING passing)

C# I have

double xCoordinate = 4820.85;
double yCoordinate = 9792.93;
string stringName = "My string stuff";
abc.Highlight(xCoordinate, yCoordinate, stringName);

In C++ / CLI I wish to receive the string (double seems just fine)

I read about the following

C++ --> std::wstring
or in C++  -->  extern "C" __declspec void GetString( char* buffer, int* bufferSize );
C# --> void GetString( StringBuilder buffer, ref int bufferSize );

Perhaps

System::String^
const char *

? So it seems that I just wish to send string from C# to C++ / CLI while it would seem simple enough, I'm not trained in C++ and finding examples of Interop /marshalling does not seem so trivial.

Upvotes: 5

Views: 3265

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564373

If you're using C++/CLI, you can use String directly:

void Highlight(double xCoordinate, double yCoordinate, String^ name)
{
    //...

Upvotes: 5

Related Questions