万恶的VB6,不上调试器都不知道咋回事...

前端之家收集整理的这篇文章主要介绍了万恶的VB6,不上调试器都不知道咋回事...前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

tMenu是个232自己的结构,想把File对象的内容用CopyMemory拷贝到这个区域,结果...没搞明白.

Private Sub Command1_Click()
Dim mObj As tMenu,b As String
Dim pMenu As Long,ret As Long
Dim mMenu As Menu
Set mMenu = File '这里小心
pMenu = VarPtr(mMenu)
CopyMemory pMenu,ByVal pMenu,4&
CopyMemory mObj,LenB(mObj)
End Sub


Private Sub Command2_Click()
Dim mObj As tMenu,ret As Long
CopyMemory pMenu,ByVal VarPtr(File),4& '这里非常小心
CopyMemory mObj,LenB(mObj)
End Sub


Private Sub Command3_Click()
Dim mObj As tMenu,ret As Long
Dim mMenu As Menu
pMenu = VarPtr(File)
CopyMemory pMenu,LenB(mObj)
End Sub

这三个过程,cmd1和cmd2效果相同,cmd3失败了,nnd,vb把对象释放了,释放的太及时了.

cmd1用了参考,通过参考能到对象,而参考要到过程结束才用了_vbaFreeObj

cmd2为什么和cmd1效果相同.第一个CopyMemory之后才用了_vbaFreeObj

cmd3在第一个Varptr之后立即用了_vbaFreeObj


理解起来还真难.

原文链接:https://www.f2er.com/vb/259950.html

猜你在找的VB相关文章