Quote Originally Posted by Agilaz
and how do you explain the following ...

VB Code:
  1. Option Explicit
  2.  
  3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSrc As Any, ByVal cbLen As Long)
  4.  
  5. Private lngStrPtr As Long
  6.  
  7.  
  8. Private Sub Command1_Click()
  9.    
  10.     'get the pointer to the constant string
  11.     lngStrPtr = StrPtr("i'm a local constant! once you know where i'm located, you can use me in any sub or function!")
  12.    
  13. End Sub
  14.  
  15. Private Sub Command2_Click()
  16.     Dim sTest As String, lngOldPtr As Long
  17.  
  18.     'make sTest point to the constant
  19.     CopyMemory ByVal VarPtr(sTest), lngStrPtr, 4&
  20.    
  21.     MsgBox sTest
  22.    
  23.     'clean up and restore the old string pointer (NULL)
  24.     CopyMemory ByVal VarPtr(sTest), vbNullString, 4&
  25.    
  26. End Sub

click command1 then command2.
The only thing that proved is that you may read from the memory already allocated by the program. The local string is no longer in use however the memory haven't been overwritten by something else yet so it still contains the same text. I fail to see the point.