A problem when using c# dlls in the C++ projects

  • Thread starter Thread starter Vivienne
  • Start date Start date
V

Vivienne

hi,

I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-> getResult();

std::string str; // here I want to copy result to str, then I can use
the string freely. But I don't know how to do it.

Is there any way ?

Thanks!

Vivienne
 
Vivienne said:
hi,

I am using a C# library in my C++ project. I want to make use of the
classes defined in the library to do some job, and use the return
value to go on other works in my project. But it seem difficult to
convert a return value of C# datatype into C++ complaint datatype,
like convert System::String in C# into std::string in C++.

like in my test code:

ClassA ^a = gcnew ClassA(); // ClassA is a class in the C# library
System::String result = a-> getResult();

std::string str; // here I want to copy result to str, then I can use

wchar_t* pinResult = result->PtrToStringChars();
std::wstring str(pinResult, result->Length);
 
Back
Top