IHostMemoryManager::VirtualProtect Method

Serves as a logical wrapper for the corresponding Win32 function. The Win32 implementation of VirtualProtect changes the protection on a region of committed pages in the virtual address space of the calling process.


HRESULT VirtualProtect (  
    [in]  void*   lpAddress,  
    [in]  SIZE_T  dwSize,  
    [in]  DWORD   flNewProtect,  
    [out] DWORD*  pflOldProtect  


[in] A pointer to the base address of the virtual memory whose protection attributes are to be changed.

[in] The size, in bytes, of the region of memory pages to be changed.

[in] The type of memory protection to apply.

[out] A pointer to the previous memory protection value.

Return Value

HRESULT Description
S_OK VirtualProtect returned successfully.
HOST_E_CLRNOTAVAILABLE The common language runtime (CLR) has not been loaded into a process, or the CLR is in a state in which it cannot run managed code or process the call successfully.
HOST_E_TIMEOUT The call timed out.
HOST_E_NOT_OWNER The caller does not own the lock.
HOST_E_ABANDONED An event was canceled while a blocked thread or fiber was waiting on it.
E_FAIL An unknown catastrophic failure occurred. When a method returns E_FAIL, the CLR is no longer usable within the process. Subsequent calls to hosting methods return HOST_E_CLRNOTAVAILABLE.


This implementation of VirtualProtect returns an HRESULT value, while the Win32 implementation returns a non-zero value to indicate success, and a zero value to indicate failure. For more information, see the Windows Platform documentation.


Platforms: See System Requirements.

Header: MSCorEE.h

Library: Included as a resource in MSCorEE.dll

.NET Framework Versions: Available since 2.0

See Also

IHostMemoryManager Interface