|
Overview |
|
|
|
Group |
|
|
|
Quick Info
Windows NT
| Yes
| Win95
| Yes
| Win32s
| Yes
| Import Library
| kernel32.lib
| Header File
| winbase.h
| Unicode
| No
| Platform Notes
| None
|
|
|
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
Points 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.
dwSize
Specifies the size, in bytes, of the region whose access protection attributes
are to be changed. The region of affected pages includes all pages containing
one or more bytes in the range from the lpAddress parameter to (lpAddress+dwSize). This means that a 2-byte range straddling a page boundary causes the
protection attributes of both pages to be changed.
flNewProtect
Specifies the new access protection. You can specify any one of the following
flags, along with the PAGE_GUARD and PAGE_NOCACHE protection modifier flags, as
necessary:
Value
| Meaning
| PAGE_READONLY
| Enables read access to the committed region of pages. An attempt to write to
the committed region results in an access violation. If the system
differentiates between read-only access and execute access, an attempt to execute code in
the committed region results in an access violation.
| PAGE_READWRITE
| Enables both read and write access to the committed region of pages.
| PAGE_WRITECOPY
| Gives copy-on-write access to the committed region of pages.
| PAGE_EXECUTE
| Enables execute access to the committed region of pages. An attempt to read or
write to the committed region results in an access violation.
| PAGE_EXECUTE_READ
| Enables execute and read access to the committed region of pages. An attempt
to write to the committed region results in an access violation.
| PAGE_EXECUTE_READWRITE
| Enables execute, read, and write access to the committed region of pages.
| PAGE_EXECUTE_WRITECOPY
| Enables execute, read, and write access to the committed region of pages. The
pages are shared read-on-write and copy-on-write.
| PAGE_GUARD
| Pages in the region become guard pages. Any attempt to access a guard page
causes the operating system to raise a STATUS_GUARD_PAGE exception and turn off
the guard page status. Guard pages thus act as a one-shot access alarm.
The PAGE_GUARD flag is a page protection modifier. An application uses it with
one of the other page protection flags, with one exception: it cannot be used
with PAGE_NOACCESS. When an access attempt leads the operating system to turn
off guard page status, the underlying page protection takes over.
If a guard page exception occurs during a system service, the service
typically returns a failure status indicator.
| PAGE_NOACCESS
| Disables all access to the committed region of pages. An attempt to read from,
write to, or execute in the committed region results in an access violation
exception, called a general protection (GP) fault.
| PAGE_NOCACHE
| Allows no caching of the committed regions of pages. The hardware attributes
for the physical memory should be specified as "no cache." This is not
recommended for general usage. It is useful for device drivers; for example, mapping a
video frame buffer with no caching. This flag is a page protection modifier,
only valid when used with one of the page protections other than PAGE_NOACCESS.
|
lpflOldProtect
Points to a variable that the function sets to the previous access protection
value of the first page in the specified region of pages. If this parameter is
NULL or does not point to a valid variable, the function fails.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
You can set the access protection value on committed pages only. If the state
of any page in the specified region is not committed, the function fails and
returns without modifying the access protection of any pages in the specified
region.
The VirtualProtect function changes the access protection of memory in the calling process, and
the VirtualProtectEx function changes the access protection of memory in a specified process.
The PAGE_GUARD protection modifier flag establishes guard pages. Guard pages
act as one-shot access alarms. See Guard Pages for further discussion of guard pages.
See Also
VirtualAlloc, VirtualProtectEx
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|