Search notes:

VBA runtime libarary msvbvm60

The DLL msvbvm60.dll does not seem to be available anymore on either Windows 10 or a 64-bit VBA environment.
option explicit


declare sub      GetMem1          lib "msvbvm60.dll" (byVal addr as longPtr,       retVal As byte    )
declare sub      GetMem2          lib "msvbvm60.dll" (byVal addr as longPtr,       retVal As integer )
declare sub      GetMem4          lib "msvbvm60.dll" (byVal addr as longPtr,       retVal As long    )
declare sub      GetMem8          lib "msvbvm60.dll" (byVal addr as longPtr,       retVal As currency)

declare sub      PutMem1          lib "msvbvm60.dll" (byVal addr as longPtr, byVal newVal As byte    )
declare sub      PutMem2          lib "msvbvm60.dll" (byVal addr as longPtr, byVal newVal As integer )
declare sub      PutMem4          lib "msvbvm60.dll" (byVal addr as longPtr, byVal newVal As long    )
declare sub      PutMem8          lib "msvbvm60.dll" (byVal addr as longPtr, byVal newVal As currency)

' declare function VarPtr           lib "msvbvm60.dll" (byVal ptr  as long) as long

declare function vbaVarAdd        lib "msvbvm60.dll" alias "__vbaVarAdd" (var1 as variant, var2 as variant) as variant
declare Function vbaVarSub        lib "msvbvm60.dll" alias "__vbaVarSub" (var1 as variant, var2 as variant) as variant
declare function vbaVarMul        lib "msvbvm60.dll" alias "__vbaVarMul" (var1 as variant, var2 as variant) as variant
declare function vbaVarCat        lib "msvbvm60.dll" alias "__vbaVarCat" (var1 as variant, var2 as variant) as variant

' vbaCopyBytes* {
'
'       vbaCopyBytes: similar to RtlMoveMemory although for non-overlapping memory only.
declare function vbaCopyBytes     lib "msvbvm60.dll" alias "__vbaCopyBytes"     (byVal length as long, dst as any, src as any) as long
'
'       vbaCopyBytesZero: Might be __vbaCopyBytes, followed by zeroing out the source memory block with zeroes.
'                         But what do I know?
declare function vbaCopyBytesZero lib "msvbvm60.dll" alias "__vbaCopyBytesZero" (byVal length as long, dst as any, src as any) as long
' }

declare function vbaObjSetAddref  lib "msvbvm60.dll" alias "__vbaObjSetAddref"  (dstObject as any, byVal srcObjPtr as long) as long
declare function vbaObjSet        lib "msvbvm60.dll" alias "__vbaObjSet"        (dstObject as any, byVal srcObjPtr as long) as long

function GetMem1_(byVal addr as longPtr) as byte ' {
    GetMem1 addr, GetMem1_
end function ' }

function GetMem2_(byVal addr as longPtr) as integer ' {
    GetMem2 addr, GetMem2_
end function ' }

function GetMem4_(byVal addr as longPtr) as long ' {
    GetMem4 addr, GetMem4_
end function ' }

function GetMem8_(byVal addr as longPtr) as currency ' {
    GetMem8 addr, GetMem8_
end function ' }
Github repository about-VBA, path: /runtime-lib/msvbvm60.bas

Directly reading and writing into and from memory

option explicit

sub main()
    dim vLong  as long
    dim ptr    as longPtr

    vLong =  3&               +  _
             5& * 256         +  _
             7& * 256*256     +  _
            11& * 256*256*256

    ptr = varPtr(vLong)

    printBytes ptr, 4

    PutMem1 ptr + 0, 0
    PutMem1 ptr + 1, 1
    PutMem1 ptr + 2, 0
    PutMem1 ptr + 3, 0

    debug.print vLong ' 256

end sub



sub printBytes(startAddr as longPtr, cnt as long) ' {

   dim addr as longPtr
   dim b    as byte

   for addr = startAddr to startAddr + cnt - 1
       call  GetMem1(addr, b)
       debug.print b

   next addr

end sub ' }
Github repository about-VBA, path: /runtime-lib/get-put-mem.bas

Adding and concatenating variables

option explicit

sub main()

   dim str as variant
   dim lng as variant

   str = "42"
   lng =   8

   debug.print vbaVarCat(str, lng) ' 842
   debug.print vbaVarAdd(str, lng) '  50

end sub
Github repository about-VBA, path: /runtime-lib/add-cat.bas

vbaObjSetAddRef

sub main()

    dim coll as new collection
    dim obj  as object

    coll.add "foo"
    coll.add "bar"

  '
  ' The following call seems to be equivalent to
  '
  '      set obj = coll
  '
    call vbaObjSetAddRef(obj, objPtr(coll))

  '
  ' obj now refers to the same object as coll. Thus,
  ' adding "baz" to obj is ...
  '
    obj.add "baz"

  '
  ' ... reflected in coll. Iterating over coll's
  ' items prints baz as well.
  '
    dim i as variant
    for each i in coll
        debug.print i
    next i

end sub
Github repository about-VBA, path: /runtime-lib/vbaObjSetAddRef.bas

See also

The example(s) on varPtr and strPtr use GetMem1 to access the memory that is returned with varPtr(string).
Runtime library VBE7

Index