[The CHString class is part of the WMI Provider Framework which is now considered in final state, and no further development, enhancements, or updates will be available for non-security related issues affecting these libraries. The MI APIs should be used for all new development.]
The GetBufferSetLength method returns a pointer to the internal character buffer for the CHString object, truncating or increasing its length if necessary to exactly match the length specified in nNewLength.
LPWSTR throw(CHeap_Exception) GetBufferSetLength( int nNewLength );
Exact size of the CHString character buffer, measured in characters.
Returns an LPWSTR pointer to the object's (NULL-terminated) character buffer.
The returned LPWSTR pointer, which is not const, allows direct modification of CHString contents.
After a call to ReleaseBuffer, the address returned by GetBufferSetLength may not be valid because additional CHString operations can cause the CHString buffer to be reallocated. If you do not change the length of the CHString string, the buffer is not reassigned. The buffer memory is freed automatically when the CHString object is destroyed.
Note that if you keep track of the string length yourself, you should not append the terminating NULL character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating NULL character when you call ReleaseBuffer, you should pass –1 (the default) for the length. The ReleaseBuffer method calls the wcslen function on the buffer to determine its length.
The following code example shows the use of CHString::GetBufferSetLength.
CHString str; LPWSTR pstr = str.GetBufferSetLength(3); pstr = 'I'; pstr = 'c'; pstr = 'e';
|Windows version||Windows Vista Windows Server 2008|
|Header||chstring.h (include FwCommon.h)|