TwCopyCDStringToLibrary (function)DescriptionThis function is related to variables of type TW_TYPE_CDSTRING (ie. C-Dynamic null-terminated Strings). It is the counterpart of the function provided to TwCopyCDStringToClientFunc.
It copies the C string
It must be used if you are adding variables of type This function is required because memory allocated by the application (your program) cannot be resized or deleted by a dynamic library (like AntTweakBar) and vice versa. Thus it should be called for copying a string in order to avoid bad memory handling between the two modules. ParametersdestPtrPointer to the destination C string handled by the AntTweakBar library. srcThe source C string handled by your application. Example
The following example adds a C-Dynamic String to a tweak bar using char *s; // ... void TW_CALL SetMyCDStringCB(const void *value, void * /*clientData*/) { // Set: copy the value of s from AntTweakBar const char *src = *(const char **)(value); free(s); s = strdup(src); } void TW_CALL GetMyCDStringCB(void *value, void * /*clientData*/) { // Get: copy the value of s to AntTweakBar char **destPtr = (char **)value; TwCopyCDStringToLibrary(destPtr, s); // use TwCopyCDStringToLibrary to copy the string } // ... s = strdup("a C-Dynamic String"); TwAddVarCB(bar, "s", TW_TYPE_CDSTRING, SetMyCDStringCB, GetMyCDStringCB, NULL, ""); // ... free(s);
See TwCopyCDStringToClientFunc for an example that uses See alsoTW_TYPE_CDSTRING, TwAddVarRW, TwAddVarRO, TwAddVarCB, TwCopyCDStringToClientFunc, string variable examples |