Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic


Tests any memory address to ensure that it is contained entirely within the program's memory space.

BOOL AfxIsValidAddress( 
   const void* lp, 
   UINT nBytes, 
   BOOL bReadWrite = TRUE  

Points to the memory address to be tested.


Contains the number of bytes of memory to be tested.


Specifies whether the memory is both for reading and writing (TRUE) or just reading (FALSE).

In debug builds, nonzero if the specified memory block is contained entirely within the program's memory space; otherwise 0.

In non-debug builds, nonzero if lp is not NULL; otherwise 0.

The address is not restricted to blocks allocated by new.

// Allocate a 5 character array, which should have a valid memory address. 
char* arr = new char[5];

// Create a null pointer, which should be an invalid memory address. 
char* null = (char*)0x0;

ASSERT(AfxIsValidAddress(arr, 5));
ASSERT(!AfxIsValidAddress(null, 5));

Header: afx.h

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.