AfxIsValidAddress
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 );
Parameters
-
lp
-
Points to the memory address to be tested.
-
nBytes
-
Contains the number of bytes of memory to be tested.
-
bReadWrite
-
Specifies whether the memory is both for reading and writing (TRUE) or just reading (FALSE).
// Allocate a 5 character array, which should have a valid memory address. char *array = new char[5]; // Create a null pointer, which should be an invalid memory address. char *null = (char *)0x0; bool Test1 = AfxIsValidAddress(array, 5); bool Test2 = AfxIsValidAddress(null, 5);
Test1 等于true 即为有效指针
Test2 等于false 即为无效指针
本文详细介绍了 AfxIsValidAddress 函数,该函数用于测试内存地址是否完全位于程序的内存空间内。文章通过示例展示了如何使用此函数检查分配的内存地址的有效性。
1279

被折叠的 条评论
为什么被折叠?



