如果得到了VB对象的地址, 并且知道该对象的类型, 那么怎么样从VB的对象地址转换得到一个VB对象(在C++中是非常简单的问题), 在VB中是不是可以实现呢? 请大家帮帮忙啊, 很急啊!

解决方案 »

  1.   

    也很简单 Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (dest As _
        Any, Source As Any, ByVal bytes As Long)Function ObjFromPtr(ByVal pObj As Long) As Object
        Dim obj As Object
        ' force the value of the pointer into the temporary object variable
        CopyMemory obj, pObj, 4
        ' assign to the result (this increments the ref counter)
        Set ObjFromPtr = obj
        ' manually destroy the temporary object variable 
        ' (if you omit this step you'll get a GPF!)
        CopyMemory obj, 0&, 4
    End Function
      

  2.   

    非常感谢! 不过为什么在CopyMemory obj, pObj, 4这句就系统出错了呢?
      

  3.   

    详细函数信息来自:http://www.freevbcode.com/ShowCode.asp?ID=230这个函数没有错误,可能是你的地址不正确,最好用objptr()取得