CopyMemory 是这样用的
两个text 一个command1Private Declare Sub CopyMemoryH2S Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal dst As String, ByVal _
src As Long, ByVal SIZE As Long)
Private Declare Sub CopyMemoryS2H Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal dst As Long, ByVal src _
As String, ByVal SIZE As Long)
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal _
wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem _
As Long) As Long
Const GMEM_FIXED = &H0
Private Sub Command1_Click()
Dim mHandle As Long
Dim astr As String * 256
Dim bstr As String * 256
astr = Left$(Text1.Text, 255)
'分配一个300字节的内存块
mHandle = GlobalAlloc(GMEM_FIXED, 300)
'将字符串中的内容拷贝到分配的内存块中
CopyMemoryS2H mHandle, astr, 255
'将内存块的内容拷贝到字符串中
CopyMemoryH2S bstr, mHandle, 255
Text2.Text = bstr
GlobalFree mHandleEnd Sub
两个text 一个command1Private Declare Sub CopyMemoryH2S Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal dst As String, ByVal _
src As Long, ByVal SIZE As Long)
Private Declare Sub CopyMemoryS2H Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal dst As Long, ByVal src _
As String, ByVal SIZE As Long)
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal _
wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem _
As Long) As Long
Const GMEM_FIXED = &H0
Private Sub Command1_Click()
Dim mHandle As Long
Dim astr As String * 256
Dim bstr As String * 256
astr = Left$(Text1.Text, 255)
'分配一个300字节的内存块
mHandle = GlobalAlloc(GMEM_FIXED, 300)
'将字符串中的内容拷贝到分配的内存块中
CopyMemoryS2H mHandle, astr, 255
'将内存块的内容拷贝到字符串中
CopyMemoryH2S bstr, mHandle, 255
Text2.Text = bstr
GlobalFree mHandleEnd Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货