SOLVED!
std::string -> GS::uchar_t gdl parameter
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-10-07 06:29 PM - last edited on ‎2022-09-29 10:10 AM by Daniel Kassai
‎2019-10-07
06:29 PM
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:
So how should i transfere my string to get it working? I always had issues with string especially unistrings/unichars.
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:
//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 crashbut 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.
Solved! Go to Solution.
Labels:
- Labels:
-
Add-On (C++)
1 ACCEPTED SOLUTION
Accepted Solutions
Solution
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-10-08 10:33 AM
‎2019-10-08
10:33 AM
Hi,
This should work:
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.
This should work:
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
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.
2 REPLIES 2
Solution
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-10-08 10:33 AM
‎2019-10-08
10:33 AM
Hi,
This should work:
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.
This should work:
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
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.
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-10-08 11:01 AM
‎2019-10-08
11:01 AM
Thank you very much this is helped a lot to understand pointers as well because i didn't used a lot c++.