12-12-2005 11:59 AM
12-12-2005 12:34 PM
Hi Dara,
to retrieve a stringe input into a string / ring control you need an array of chars, not a single char which is actually a single character / byte value. Second, the name of a string array is itself a pointer to the first element of the array and so a pointer to the whole string.
Given this, I suggest you modify your code as follows:
12-12-2005 01:13 PM
Typically you know how long the text in the ring control should be (so you make your character array variable atleast that long plus one--for the null byte). If you don't have any clue how long it will be then you can do it another way, but it is much more complicated than just picking some really big 'safe' length. Unfortunately, if you use the 'safe' length and then some user comes along and types something in that is longer than your program is prepared for, then the 'safe' length won't be safe anymore. There is a whole class of software exploits that take advantage of fixed length string buffers. This should work better (99.99% of the time).
char *string;
int length, index;
GetCtrlIndex(panel, PANEL_RING_1, &index);
GetCtrlValStringLength(panel, PANEL_RING_1, &length);
string = malloc(sizeof(char) * (length + 1));
GetCtrlVal(panel, PANEL_RING_1, string);
printf("%s", string);
free(string);
12-13-2005 02:15 AM - edited 12-13-2005 02:15 AM
You will also find useful AllocateCtrlValString function that does allocate the exact string for retrieving control text. Be sure to free the string after you have used it and to pass a correct control type to the function, otherwise you will receive error -10 (control is not of the type expected by the function) and the string will remain unchanged. You can use this function as follows:
int error;
char *string = NULL;
error = AllocateCtrlValString (panel, impo_list, &string);
// "string" contains control text
if (string) free (string);
Unfortunately you cannot use neither AllocateCtrlValString nor GetCtrlValStringLength on rings as their data type is numeric type (integer, double...) while these functions expect a datatype of char.
Message Edited by Roberto Bozzolo on 12-13-2005 09:15 AM
12-13-2005 10:50 AM
12-13-2005 11:06 AM
Orlan, you're right that a ring control can have a char * datatype: it hasn't come to my mind since I use this option very rarely, but indeed it's true. Thanks to have pointed us to this facility.
Roberto
12-13-2005 07:58 PM
Hey Dara,
Hopefully you have more than enough input there! It's actually quite difficult to catch Roberto off guard. He's quite helpful on the board, to me as well, on numerous occasions. Please post again and any of us will do our best to help you out.
Good luck,
Orlan
12-16-2005 04:20 AM
Hi , thank you very much for all your help Orlan and Roberto.
Your advices have been very helpfull and hope I could reach your level one day
See U.