VB使用函数指针~高手来 很值得研究
网上 某某大师的vb函数指针看不懂
不懂汇编 ~~~ 等等~ 很多不懂
vb想使用函数指针难啊
目前搞出个东西,当然也就错的一塌糊涂了,不过有点效果
现在就想求高手给点帮助
在标准模块里搞一个空函数 一个fun2
public function Fun1(byval v as long ) as long
end function
public function Fun2(byval v as long ) as long
Debug.Print "fun2->" & v
end function
'form1
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
dim orifp as long
dim fp as long
dim callfp as long
Private Sub Form_Load()
CopyMemory orifp, GetFunAddr(AddressOf Fun1) + 22, 4
CopyMemory Fp, ByVal orifp, 4
CopyMemory orifp, ByVal Fp + 1, 4
CopyMemory callfp, GetFunAddr(AddressOf Fun2) + 22, 4
CopyMemory callfp, ByVal callfp, 4
CopyMemory callfp, ByVal callfp + 1, 4
CopyMemory ByVal Fp + 1, callfp, 4
Fun2 12345&
end sub
Private Function GetFunAddr(ByVal addr As Long) As Long
GetFunAddr = addr
End Function
'结果 fun2-> 12345
’以上代码供大家测试一下 调用一次可以 多次就要死 IDE了
'希望高手不要藏私啊
[解决办法]
楼主这复制的是哪里的代码啊:)
[解决办法]
绕得我头晕!一堆代码不知道在做什么.
其实就是一句代码的事情.
Option ExplicitPrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Private Sub Form_Load() CopyMemory GetFunAddr(AddressOf Fun2), GetFunAddr(AddressOf Fun1), 4 Fun1 12345&End SubPrivate Function GetFunAddr(ByVal addr As Long) As Long GetFunAddr = addrEnd Function
[解决办法]
.....................
[解决办法]
VB?指针?!
我还是第一次听说,VB时不支持指针操作的,顶多就是模拟指针操作,操作一下内存地址而已。
[解决办法]
顶一下,学习下``````````````````
[解决办法]
你拿我的代码去运行一下.
我也是调用 Fun1 12345& 但显示了 fun2->12358
你之前的那些代码没意义(至少我看不懂)
这一句就够了: CopyMemory GetFunAddr(AddressOf Fun2), GetFunAddr(AddressOf Fun1), 4