|
本帖最后由 Tesla.Angela 于 2010-7-21 09:44 编辑
就是集成了的指针操作的函数,能方便地操作BYTE、WORD、LONG、Single、Double、BSTR和UNICODE_STRING的指针。
'//////////////////////////////
'VB Pointer Class v0.1
'Code By Tesla.Angela(GDUT.HWL)
'//////////////////////////////
Option Explicit
Private Type UNICODE_STRING
Length As Integer
MaxLength As Integer
pBuffer As Long
End Type
Private Declare Function lstrlenW Lib "KERNEL32" (ByVal lpString As Long) As Long
Private Declare Function lstrcpyW Lib "KERNEL32" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (ByVal pDst As Long, ByVal pSrc As Long, ByVal dwLength As Long)
Public Function ChrFromPtr(ByVal pChr As Long) As Byte
RtlMoveMemory VarPtr(ChrFromPtr), pChr, 1
End Function
Public Function IntFromPtr(ByVal pInt As Long) As Integer
RtlMoveMemory VarPtr(IntFromPtr), pInt, 2
End Function
Public Function LngFromPtr(ByVal pLng As Long) As Long
RtlMoveMemory VarPtr(LngFromPtr), pLng, 4
End Function
Public Function SngFromPtr(ByVal pSng As Long) As Single
RtlMoveMemory VarPtr(SngFromPtr), pSng, 4
End Function
Public Function DblFromPtr(ByVal pDbl As Long) As Double
RtlMoveMemory VarPtr(DblFromPtr), pDbl, 8
End Function
Public Function StrFromBsPtr(ByVal pString As Long) As String
StrFromBsPtr = String(lstrlenW(pString), Chr(0))
lstrcpyW StrPtr(StrFromBsPtr), pString
End Function
Public Function StrFromUsPtr(ByVal pUnicodeString As Long) As String
Dim uStr As UNICODE_STRING
RtlMoveMemory VarPtr(uStr), pUnicodeString, 8
StrFromUsPtr = Space(uStr.Length / 2)
RtlMoveMemory VarPtr(StrFromUsPtr), VarPtr(uStr.pBuffer), 4
End Function |
|