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

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
 
B

Ben Voigt [C++ MVP]

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top