Results 1 to 5 of 5

Thread: [RESOLVED] Trimming Nulls with SysReAllocString

Threaded View

  1. #1

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Resolved [RESOLVED] Trimming Nulls with SysReAllocString

    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:

    The address passed in psz cannot be part of the string passed in pbstr, or unexpected results may occur.
    Here is a sample usage:

    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
    I hope somebody can shed light on this...
    Last edited by Bonnie West; Jun 29th, 2012 at 02:42 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width