Archicad C++ API
About Archicad add-on development using the C++ API.

Convert GS::UniString to char*

Docmatic
Participant

Hi guys,  I am tryng to use curl_lib in my Archicad Addon.   How can I convert a GS::Unistring to  char*

 

Thank you

2 REPLIES 2
Miha Nahtigal
Advocate
const char* cString = gsUniString.ToCStr().Get();
BIMquants.comBETA - Quantities and Costs Estimation in Archicad - BETA testers needed.
Miklos Vegh
Graphisoft
Graphisoft

You should not instantiate a pointer with the result of ustr.ToCStr().Get().

The ToCStr() returns a CStr object which is created on the stack. When the next statement is executed the CStr object will be destroyed resulting an invalid pointer.

Use .ToCStr().Get() in function parameters only.

 

If you want to have a pointer use ustr.CopyUTF8 ()  instead, which returns a pointer to a newly allocated copy. This needs to be freed with delete[].