Using Lstrcpy() API Function to Get Far Address of a VariableID: Q94700
|
You can use the Windows API function Lstrcpy() to get the far address of
a variable as a Long integer.
The Lstrcpy() function returns the same value as its first argument, which
is the address of a variable. Usually you would use the Lstrcpy() function
to copy strings that are terminated by a zero byte. However, if you pass
the same variable as both the source and the destination, Lstrcpy() copies
the variable to itself, which has no effect.
Basic cannot deal with pointers directly. All Basic can do with a pointer
is pass it as a parameter to a DLL function.
Basic variables may move in memory. You should take the address of a
variable immediately before you use it.
The following steps demonstrate how to get the address of an integer and a
variable-length string.
Declare Function Lstrcpy Lib "kernel" (p1 As Any, p2 As Any) As Long
Sub Form_Click ()
Dim ptr As Long ' pointer value
Dim x1 As Integer ' variable to take address of
Dim x2 As String ' variable to take address of
x1 = 123
ptr = Lstrcpy(x1, x1)
MsgBox "The address of x1 is: " + Hex$(ptr)
x2 = "x2"
' must use ByVal on variable length strings
ptr = Lstrcpy(ByVal x2, ByVal x2)
MsgBox "The address of x2 is: " + Hex$(ptr)
End Sub
Additional query words: 1.00 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 21, 1999