Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Enum MyVarType
longVar
byteVar
integerVar
DoubleVar
CurrencyVar
DateVar
SingleVar
BoolVar
StringVar
End Enum
Function Indirection(ByVal lpointer As Long, DataType As MyVarType) As Variant
Select Case DataType
'declare each "Dest" var according to the passed DataType
'Enum argument before copying the passed pointer to them.
Case Is = MyVarType.byteVar
Dim bDest As Byte
CopyMemory bDest, ByVal lpointer, LenB(bDest)
Indirection = bDest
Case Is = MyVarType.integerVar
Dim iDest As Integer
CopyMemory iDest, ByVal lpointer, LenB(iDest)
Indirection = iDest
Case Is = MyVarType.DoubleVar
Dim dDest As Double
CopyMemory dDest, ByVal lpointer, LenB(dDest)
Indirection = dDest
Case Is = MyVarType.CurrencyVar
Dim cDest As Currency
CopyMemory cDest, ByVal lpointer, LenB(cDest)
Indirection = cDest
Case Is = MyVarType.DateVar
Dim dtDest As Date
CopyMemory dtDest, ByVal lpointer, LenB(dtDest)
Indirection = dtDest
Case Is = MyVarType.SingleVar
Dim sDest As Single
CopyMemory sDest, ByVal lpointer, LenB(sDest)
Indirection = sDest
Case Is = MyVarType.longVar
Dim lDest As Long
CopyMemory lDest, ByVal lpointer, LenB(lDest)
Indirection = lDest
Case Is = MyVarType.BoolVar
Dim blDest As Boolean
CopyMemory blDest, ByVal lpointer, LenB(blDest)
Indirection = blDest
Case Is = MyVarType.StringVar
Dim stDest As String
stDest = String$(1000, " ")
CopyMemory ByVal StrPtr(stDest), ByVal lpointer, Len(stDest) - 1
Indirection = stDest
End Select
End Function