-2

I've been struggling with a new project in C++/CLI. I managed to fix most of my problems on this language (most of them were about translation from either C# or native C++ codes). But I still have one big problem:

I'm using a (native) C++ library as unmanaged code to retrieve information on images and stuff (basic OCR). This library gives me specific types on output. Most of them are either bool or int, so I can handle them in C++/cli, but I have a non-standard string output format (gxOutString) that I can't process. I just get an error saying:

m_codeString = reader.GetCodeString();
"there is no conversion between "gxOutString" and "System::String ^"

I know the images are processed and the code string recognized by the library (because checksum validations are returned true, also other variables checks out), but I haven't managed to do anything with this string which is the most important element to retrieve.

In console native C++ though, this variable can be printed in cout normally, and handled by C++ in Qt via QtString apparently (from other programs I have as examples).

How can I process this type so the rest of the managed C++/cli code can understand it?

ChuckMaurice
  • 111
  • 7
  • Look at the documentation for that library and see if they have any conversions to c-strings or C++ strings. If you can get that, then it is easy to get to a `System::String^`. – crashmstr Mar 24 '17 at 11:46
  • I didn't found anything in the library documentation but I remember some components are handled with yet another library we don't have the doc for, but we have some of the source code. Exploring those files I found this reference: `typedef std::string gxOutAString;` `typedef std::wstring gxOutString;` So looks like it's just a _std::string_. Gonna have some fun with the Marshall then... – ChuckMaurice Mar 24 '17 at 13:23
  • 1
    Pretty simple, actually: `x = marshal_as(cppstring);` – crashmstr Mar 24 '17 at 13:38
  • Is this way better than the one I described as an answer? – ChuckMaurice Mar 24 '17 at 13:42

1 Answers1

-2

So after some more investigation I found two references in a header (from yet another library I use):

typedef std::string gxOutAString;
typedef std::wstring gxOutString;

So turns out it's a std::string after all.

My solution for conversion then:

gxOutAString temp_codeString = reader.GetCodeString();
m_codeString = gcnew String(temp_codeString.c_str());

Seems to work fine even if I'm still figuring out how the Marshall works for "reverse" conversions. Thank you anyway. That's incredible how a crippling error can be fixed just by explaining it and getting small suggestions.

ChuckMaurice
  • 111
  • 7