TwCopyCDStringToLibrary (function)

void TwCopyCDStringToLibrary(char **destPtr, const char *src)


This 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 src handled by the client application (your program) to the C string dest handled by the AntTweakBar library.

It must be used if you are adding variables of type TW_TYPE_CDSTRING to a tweak bar using TwAddVarCB in order to manage the variable through callback functions. See the example below.

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.



Pointer to the destination C string handled by the AntTweakBar library.


The source C string handled by your application.


The following example adds a C-Dynamic String to a tweak bar using TwAddVarCB which requires the use of TwCopyCDStringToLibrary.

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);
  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, "");
// ...

See TwCopyCDStringToClientFunc for an example that uses TwAddVarRW.

See also