|
-
Jul 20th, 2006, 08:37 AM
#16
Re: what is a difference between function,sub and property
 Originally Posted by Agilaz
and how do you explain the following ...
VB Code:
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSrc As Any, ByVal cbLen As Long)
Private lngStrPtr As Long
Private Sub Command1_Click()
'get the pointer to the constant string
lngStrPtr = StrPtr("i'm a local constant! once you know where i'm located, you can use me in any sub or function!")
End Sub
Private Sub Command2_Click()
Dim sTest As String, lngOldPtr As Long
'make sTest point to the constant
CopyMemory ByVal VarPtr(sTest), lngStrPtr, 4&
MsgBox sTest
'clean up and restore the old string pointer (NULL)
CopyMemory ByVal VarPtr(sTest), vbNullString, 4&
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|