Declare Sub FillMemory Lib "kernel32.dll" Alias "RtlFillMemory" (Destination As Any, ByVal Length As Long, ByVal Fill As Byte)
FillMemory fills a location in memory with a certain value. The function does this by setting each byte starting at the given memory location to the desired value. The memory location is identified by a pointer to the memory address.
FillMemory does not return a value.
A pointer to any variable can be automatically generated merely by passing that variable as Destination. However, if either a String or a Long holding the desired memory address is passed, the ByVal keyword must preceed it. See the example below for a demonstration.
' This code is licensed according to the terms and conditions listed here.
' Initialize all the elements in an array of bytes to the value 76. Also
' set each character in a 20-character string to the character "X".
Dim bytearray(0 To 9) As Byte ' array of 10 bytes
Dim bytestring As String ' string to fill
Dim c As Integer ' counter variable
' Fill the memory at bytearray() in order to initialize its members to 76. Note that, to
' identify the pointer to bytearray()'s memory, it is passed as normal.
FillMemory bytearray(0), 10, 76 ' fill 10 bytes to the byte value 76
' Display the results to verify that it worked.
For c = 0 To 9 ' loop through each element
Debug.Print bytearray(c); ' each value displayed will be 76
Next c
' Now fill a 20-character string with "X" (using its ASCII code). Note how, in Visual
' Basic, the ByVal keyword must preceed the string in this case.
bytestring = Space(20) ' make the string 20 characters long
FillMemory ByVal bytestring, 20, Asc("X") ' set the contents to a bunch of "X"'s
' Display the results to verify that it worked.
Debug.Print bytestring ' will be twenty X's
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: July 25, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/f/fillmemory.html