日期:2014-05-17  浏览次数:21915 次

VirtualProtect函数失败
用malloc函数申请了一块内存地址,返回指针为pbyteMemory,通过VirtualProtect函数更改,申请的这一块儿内存为可读可写属性,但是,函数执行失败,返GetLastError函数返回值0x3E6。求解……

------解决方案--------------------
GetLastError函数返回值0x3E6 : 998 Invalid access to memory location. ERROR_NOACCESS 


VirtualProtect
The VirtualProtect function changes the access protection on a region of committed pages in the virtual address space of the calling process. This function differs from VirtualProtectEx, which changes the access protection of any process.

BOOL VirtualProtect(
LPVOID lpAddress, // address of region of committed pages
DWORD dwSize, // size of the region
DWORD flNewProtect, // desired access protection
PDWORD lpflOldProtect 
// address of variable to get old protection
);
 
Parameters
lpAddress 
Pointer to the base address of the region of pages whose access protection attributes are to be changed. 
All pages in the specified region must have been allocated in a single call to the VirtualAlloc or VirtualAllocEx function. The pages cannot span adjacent regions that were allocated by separate calls to VirtualAlloc or VirtualAllocEx.