Tesla.Angela 发表于 2012-4-28 17:50:16

特大发现?在VB2010的64位程序中照样使用VarPtr!

先用VC2010制作一个DLL,核心代码只有四行:
VB10PTR_EXTDLL_API ULONG64 VarPtr(PVOID p)
{
        return (ULONG64)p;
}
然后用VB2010写个测试:
Public Class Form1
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int08 As Byte) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int08 As SByte) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int16 As UShort) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int16 As Short) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int32 As UInteger) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int32 As Integer) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int64 As ULong) As ULong
    Private Declare Function VarPtr Lib "vbNetPtr.dll" Alias "#1" (ByRef int64 As Long) As ULong
    Private Declare Sub RtlFillMemory Lib "kernel32.dll" (ByVal dst As ULong, ByVal len As ULong, ByVal chr As Byte)
    Private Declare Sub RtlMoveMemory Lib "kernel32.dll" (ByVal dst As ULong, ByVal src As ULong, ByVal len As ULong)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim xx As Integer = &HFFFFFFFF        '这里要赋值占满空间
      Dim yy As Integer = &H10191019        '这里要赋值占满空间
      Dim xx_ptr As ULong = 0, yy_ptr As ULong = 0
      MsgBox(Hex(xx), , "ffffffff")
      xx_ptr = VarPtr(xx)
      yy_ptr = VarPtr(yy)
      RtlMoveMemory(xx_ptr, yy_ptr, 4)
      MsgBox(Hex(xx), , "10191019")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      Dim xx As ULong
      Dim yy As ULong
      Dim xx_ptr As ULong = 0, yy_ptr As ULong = 0
      xx_ptr = VarPtr(xx)
      yy_ptr = VarPtr(yy)
      RtlFillMemory(xx_ptr, 8, &HFF)
      RtlFillMemory(yy_ptr, 8, &HEE)
      MsgBox(Hex(xx), , "FFFFFFFFFFFFFFFFF")
      RtlMoveMemory(xx_ptr, yy_ptr, 8)
      MsgBox(Hex(xx), , "EEEEEEEEEEEEEEEEE")
    End Sub
End Class
发现完全达到了VB6里自带VarPtr的效果!
我对.NET不太了解,不知道这样子会不会出问题,各位试用一下。bin和src都在压缩包里了。

upring 发表于 2015-4-16 10:22:24

谢谢大侠分享{:soso_e113:}
页: [1]
查看完整版本: 特大发现?在VB2010的64位程序中照样使用VarPtr!