8 out of 15 rated this helpful - Rate this topic

ZeroMemory macro

Applies to: desktop apps only

Fills a block of memory with zeros.

To avoid any undesired effects of optimizing compilers, use the SecureZeroMemory function.

Syntax

void ZeroMemory(
  [in]  PVOID Destination,
  [in]  SIZE_T Length
);

Parameters

Destination [in]

A pointer to the starting address of the block of memory to fill with zeros.

Length [in]

The size of the block of memory to fill with zeros, in bytes.

Return value

This macro has no return value.

Remarks

Many programming languages include syntax for initializing complex variables to zero. There can be differences between the results of these operations and the ZeroMemory function. Use ZeroMemory to clear a block of memory in any programming language.

This macro is defined as the RtlZeroMemory macro. For more information, see Winbase.h and Winnt.h.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Winbase.h (include Windows.h)

See also

CopyMemory
FillMemory
MoveMemory
SecureZeroMemory

 

 

Send comments about this topic to Microsoft

Build date: 2/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern void ZeroMemory(IntPtr handle, uint length);
Managed Code Alternative
The .Net Framework has a managed equivalent that's probably a better choice here:

System.Buffer.SetByte(...)

Likewise, rather than use memcpy, use the System.Buffer.BlockCopy(...) method.

I'm sure these call the underlying memcpy and memset routines, but they don't require DllImport which is troublesome, and these are slightly easier to read (YMMV).
ZeroMemory Definition

ZeroMemory() is defined in WINBASE.H as:

#define ZeroMemory RtlZeroMemory

RtlZeroMemory() is defined in WINNT.H as:

#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))

 

vb.net syntax
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Sub ZeroMemory(ByVal handle As IntPtr, ByVal length As UInt32) End Sub