Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# string passed to C++ CLI

Tags:

c#

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.

like image 349
Tom Stickel Avatar asked Apr 13 '13 00:04

Tom Stickel


1 Answers

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

void Highlight(double xCoordinate, double yCoordinate, String^ name)
{
    //...
like image 147
Reed Copsey Avatar answered Sep 30 '22 01:09

Reed Copsey