|
Type POINT X As Integer Y As Integer End Type
Public Function Compare(elem1 As Long, elem2 As Long) As Long ' End Function
Function FnPtrToLong(ByVal lngFnPtr As Long) As Long FnPtrToLong = lngFnPtr End Function
Sub PtrDemo() Dim l As Long, c As Byte, ca() As Byte, Pt As POINT Dim pl As Long, pc As Long, pv As Long, pPt As Long, pfnCompare As Long c = AscB("X") pl = VarPtr(l) '对应C里的long、int型指针 pc = VarPtr(c) '对应char、short型指针 pPt = VarPtr(Pt) '结构指针 pv = VarPtr(ca(0)) '字节数组指针,可对应任何类型,也就是void* pfnCompare = FnPtrToLong(AddressOf Compare) '函数指针 CopyMemory c, ByVal pc, LenB(c) '用指针取值 CopyMemory ByVal pc, AscB("Y"), LenB(c) '用指针赋值 pc = pc + LenB(c) : pl = pl - LenB(l) '指针移动 End Sub |