Hi! Can anybody please confirm that trimming null characters from a string using the function SysReAllocString is without any undesirable side-effect(s) such as memory leaks, etc.? MSDN has the following warning on the SysReAllocString function:
Here is a sample usage:The address passed in psz cannot be part of the string passed in pbstr, or unexpected results may occur.
I hope somebody can shed light on this...Code:Private Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long Dim sTemp As String sTemp = Space$(1048576) '1 MB Mid$(sTemp, 2&) = vbNullChar 'This function allocates a new string, 'copies the passed null-terminated string into it 'and then deallocates the old contents Debug.Print CBool(SysReAllocString(VarPtr(sTemp), StrPtr(sTemp))) Debug.Print Len(sTemp) 'prints 1 'This has the same effect as sTemp = vbNullString SysReAllocString VarPtr(sTemp) Debug.Print StrPtr(sTemp) 'prints 0![]()




Reply With Quote
