cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Special Characters in uifcLabel Text

sully7
13-Aquamarine

Special Characters in uifcLabel Text

All,

I've finally started to make the switch from traditional Pro/TOOLKIT into OTK, and ran into a quick question.

I have a uifcDialog created and working fine. Inside of that dialog, I have a uifcLabel - lets call it "CONTENT". I can set text to CONTENT using the standard

uifcLabel_ptr label = uifcLabelFind(DIALOG_NAME, CONTENT);

  label->SetTextAlignment(uifcAlignment::uifcALIGNMENT_LEFT);

xstring custom_text = "My Text";

  label->SetText(custom_text);

However, this does not seem to work when I include special characters for instance:

xstring custom_text = "© Text";

  label->SetText(custom_text);

I'm not sure if this has anything to do with it... but I loaded up the debugger, and investigated "custom_text". Inside of the __xstring_c it seems as though only the mbstr element has a value... the wstr element is NULL.

Any ideas?

As a side note... I'm testing in Creo 3, and am linking to protk_dll_NU.lib.

Thanks,

James


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
President & Founder
CadActive Technologies - www.cadactive.com
1 ACCEPTED SOLUTION

Accepted Solutions
Eike_Hauptmann
13-Aquamarine
(To:sully7)

Hi James

A college of me had the same problem some days ago. He uses a double conversion : xstring(wstring(xstring())); That don't look like a good idea ... .

I think the problem is the charset conversion. So the fillup of the Label->label is wstring. you can push it in directly in UTF16 (std. wstring) by adding L to your string.

  1. xstring custom_text = L"© Text"; 
  2. label->SetText(custom_text); 

I don't know if this change anything. But it should. So the compiler convert it for you to the UTF16 char array. Anyway. all this isn't tested by me ^^ just ideas.

Br,

Eike

View solution in original post

2 REPLIES 2
Eike_Hauptmann
13-Aquamarine
(To:sully7)

Hi James

A college of me had the same problem some days ago. He uses a double conversion : xstring(wstring(xstring())); That don't look like a good idea ... .

I think the problem is the charset conversion. So the fillup of the Label->label is wstring. you can push it in directly in UTF16 (std. wstring) by adding L to your string.

  1. xstring custom_text = L"© Text"; 
  2. label->SetText(custom_text); 

I don't know if this change anything. But it should. So the compiler convert it for you to the UTF16 char array. Anyway. all this isn't tested by me ^^ just ideas.

Br,

Eike

sully7
13-Aquamarine
(To:Eike_Hauptmann)

Eike,

Thanks for the response - funny enough, this worked! The code I had above was a simplification of the code I had been using... but I realized it was ultimately a combination of problems.

  1. At first, I had tried allocating the xstring as you mentioned,  but was receiving a linker error "LNK2019 - unresolved external symbol".
  2. After exploring a bit more, I realized this was because I had been compiling with the flag "/Zc:wchar_t-" - aka, "Treat WChar_t As Built In Type" was set to "No".
    1. I changed it to "Yes", and the Linker problem went away
  3. I typically use std::strings and std::wstring for most of my actual string handling. Since "SetText" technically takes an input of an "xrstring" (which is a const char *), I figured std::string would be more appropriate, but oddly enough, it handles the conversion from xstring, and still somehow accesses the wstr element instead of the mbcstr element (which is why your example works )
  4. As a test, I actually also tried setting the value for a uifcTextArea as well using my original code... Since uifcTextArea technically has three methods to set the same value... "SetTextValue", "SetWideStringValue", and "SetStringValue"... I figured maybe one of them would actually work. Oddly enough... all three of these functions have inputs of "xrstring" (again... const char*), and none of them worked with my original code.
    1. I've asked PTC support for a clarification between these methods - if the performance is any different, or if they differ in any way... and we'll see what they come back with.
  5. Ultimately, I had just switched over to ProUI functions instead of the uifc OTK functions... and it handled it without a problem as well because it handles in wchar_t natively.

Thanks again for the response.

President & Founder
CadActive Technologies - www.cadactive.com
Top Tags