Appendix B. Pointers

CopyMemory is used a great deal throughout the course of this book to copy memory from one location to another. Without this function, it would be impossible to use pointers in Visual Basic. Since the function does exist, it is possible to write some very dangerous VB code. A short course on CopyMemory and pointers is definitely in order.

CopyMemory

There is really no function called CopyMemory. CopyMemory is merely an alias for the Win32 function RtlMoveMemory. Bruce McKinney, the author of Hardcore Visual Basic (Microsoft Press), was probably the first to use the alias CopyMemory. Now it is quite common to see RtlMoveMemory declared in this fashion. Its syntax (as reflected in a Visual Basic Declare statement) is:

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ 
    (pDest As Any, pSource As Any, ByVal ByteLen As Long)

where pDest is a pointer to the starting target address to which data is to be copied, pSource is a pointer to the starting address from which data is to be copied, and ByteLen is the number of bytes to be copied.

Get VB Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.