User's Guide > Fundamentals > String and Widestring Functions
String and Widestring Functions
 
Creo+ provides many functions taking as inputs a fixed-length character or wide character array as a string. Due to some platform-specific behavior, PTC recommends that you do not use string literals in lieu of fixed length arrays. Always copy the literal strings to the full size array that the functions accepts as the input.
For example the following function will get warnings on certain platforms because the code expects that the arguments can be modified.
ProEngineerStart("proe_path","text_path");
where ProCharPath proe_path=”proe_path”;
ProCharPath text_path=”text_path”;
To overcome this error, it is recommended that you replace the literal strings in the function with defined arrays as follows:
ProEngineerStart(proe_path,text_path);
Functions Introduced:
Wide character strings are not as easy to manipulate in C as ordinary character strings. In general, there are no functions for wide strings that correspond to the standard C str*() functions. printf() does not have a format for wide strings, and you cannot set a wide string to a literal value in a simple assignment. Because of this, it is frequently convenient to convert wide strings to character strings, and vice versa. This is the purpose of the functions ProStringToWstring() and ProWstringToString().
The function ProWstringLengthGet() is used to find the length of a widestring.
The function ProWstringCopy() copies a widestring into another buffer. You should allocate enough memory in the target setting to perform the copy operation. The number of characters to be copied is provided as input through num_chars. Use PRO_VALUE_UNUSED to copy the entire string.
The function ProWstringCompare() compares two widestrings for equality. The two widestrings to be compared are given as inputs. The argument num_chars allows comparison of portions of the string, pass PRO_VALUE_UNUSED to compare the entire strings.
The function ProWstringConcatenate() concatenates two widestrings. You should allocate enough memory in the target string for the copy operation. The number of characters to concatenate is given as input through num_chars. Use PRO_VALUE_UNSED to add the entire source string to the target string.
The source code for other useful utilities is located in the file <TK_LOADPOINT>protk_appls\pt_examples\pt_utils\UtilString.c
Example 4: String Conversion
The sample code in UgFundStringConv.c located at <creo_toolkit_loadpoint>\protk_appls\pt_userguide\ptu_fundament uses the function UsrModelFilenameGet() to convert wide strings to character strings.
¿Fue esto útil?