Function _conWLockC() Foundation

Locks a string container for direct write access.

Syntax
XPPAPIRET _conWLockC(ContainerHandle chs, CHAR **ppstr,
                     ULONG *pulSize);
Parameters
ContainerHandle chs
Handle of a container of character string type.
CHAR **ppstr
Buffer for the returned pointer to the character string. The string is not copied, but ppstr points to the internal representation of the string. The pointer may be used to change the string but the string can not be resized while it is locked.
ULONG *pulSize
Pointer to a ULONG. After the call, this contains length of the string *ppstr points to. Note:In Xbase++ character strings may contain NULL characters.
Return

The function returns an error code (XPP_ERR_...) when the container chs is not a character string or when the write access failed (e.g. if there is already a read-lock on the container). If the return value is NULL, the operation was successful.

Description

Especially for long strings this function is used to change the value of a string container directly. The returned pointer may be used to write into the string. However, the length of the string can be changed only after write access was finished with _conUnlockC(). The call of _conUnlockC() should be done as soon as possible, as the garbage collector may be blocked otherwise.

Please note that a NULL character is guaranteed after the end of the string but the string itself may contain NULL characters, too.

If the container locked with _conWLockC() is a reference container returned from _conParam() the unlock has to be done before one of the return functions (_ret...() or _conReturn()) is called! This restriction is valid only for reference-containers and not for other parameter containers or locally created containers.

Examples
Convert first character of all words to uppercase
#include <ctype.h>        /* isalpha(), tolower(), toupper() */ 
#include "xpppar.h" 
#include "xppcon.h" 

/* 
  FT_PROPER( <cString> ) -> cProperName 

  Note: To use isalpha(), toupper() and tolower() the 
  C-library has to be initialised first! 
*/ 
XPPRET XPPENTRY FT_PROPER( XppParamList paramList ) 
{ 
ContainerHandle  chParam; 
CHAR            *pc; 
ULONG            srcLen; 
ULONG            i; 
BOOL             doCap = TRUE; 

/* 
   Get copy of parameter 1 (As long as the third parameter 
   is NULL _conParam asserts that a copy is generated 
   even when the parameter is passed by reference ) 
*/ 
chParam = _conParam( paramList, 1, NULL ); 

if (chParam != NULLCONTAINER) 
{ 
   if (! _conWLockC( chParam, &pc, &srcLen )) 
   { 
      for( i = 0; i < srcLen + 1; i++ ) 
      { 
         if( isalpha( pc[i] ) ) 
         { 
            if( doCap ) 
               pc[i] = toupper( pc[i] ); 
            else 
               pc[i] = tolower( pc[i] ); 
         } 
         doCap = ( pc[i] == ' ' || pc[i] == '-' || pc[i] == '\'' ); 
      } 

      for( i = 0; i <= srcLen; i++ ) 
         if( pc[i] == 'M' && pc[i+1] == 'c' ) 
            pc[i+2] = toupper( pc[i+2] ); 

      _conUnlockC( chParam ); 
      _conReturn( paramList, chParam ); 
   } 
   else 
      _retc( paramList, "" ); 
   _conRelease( chParam ); 
} 
else 
   _retc( paramList, "" ); 
return; 
} 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.