The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (API DevKit) for independent software developers

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, gkmethy, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik, Tibor Lorántfy, rmasaki

By HeadLess
#302463
Hi there!

I think i have a simple problem, but i couldn't get over it by myself....

I have an std::string parameter which is came from a csv file through ifstream::getline. And i have to change a library element string parameter, which is uchar_t *. But i couldn't get it converted...

so here is what i tried:
Code: Select all
//these are predefined
   std::string line;
   Int32 id;
   char paramname[32];

API_ChangeParamType  chgParam;

BNZeroMemory(&chgParam, sizeof(API_ChangeParamType));

chgParam.index = id;
strcpy(chgParam.name, paramname);
GS::ucscpy(chgParam.uStrValue, GS::UniString(line.c_str()).ToUStr().Get()); //GSReporter crash

but it is crashing during ucscpy.
So how should i transfere my string to get it working? I always had issues with string especially unistrings/unichars.
#302508
Hi,

This should work:
Code: Select all
GS::uchar_t bufferUStr[API_UAddParStrLen];
GS::ucsncpy (bufferUStr, GS::UniString (line.c_str()).ToUStr().Get(), API_UAddParStrLen - 1);
chgParam.uStrValue = bufferUStr;
Just make sure, that bufferUStr will live till you use the chgParam :wink:

A little explanation:
uStrValue is a simple pointer, it just points to somewhere. That's why you cannot write characters into it and you got crash report immediately. You have to set the pointer to an existing array of characters.