VB编程:传递指针变量

1、运行效果

VB编程:传递指针变量


2、程序代码

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Dim q As String

Dim p As String


Private Sub Command1_Click()

On Error GoTo 1

   jiaohuan p, q

   Text1.Text = q

   Text2.Text = p

1: End Sub


Private Sub Form_Load()

   q = "abcdel"

   p = "123456"

   Text1.Text = q

   Text2.Text = p

End Sub


Private Function jiaohuan(ByRef str1 As String, ByRef str2 As String)

   Dim p

   CopyMemory ByVal VarPtr(p), ByVal VarPtr(str2), 4

   CopyMemory ByVal VarPtr(str2), ByVal VarPtr(str1), 4

   CopyMemory ByVal VarPtr(str1), ByVal VarPtr(p), 4

End Function


上一篇:VB编程:利用指针实现数组拆分


下一篇:VB编程:利用地址偏移访问内存