WinStd
Additional templates and function helpers for Microsoft Windows using Standard C++ classes
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
winstd::vmemory Class Reference

Memory in virtual address space of a process handle wrapper. More...

#include <Win.h>

Inheritance diagram for winstd::vmemory:
winstd::handle< LPVOID, NULL >

Public Member Functions

 vmemory () noexcept
 Initializes a new class instance with the memory handle set to INVAL.
 
 vmemory (_In_ handle_type h, _In_ HANDLE proc) noexcept
 Initializes a new class instance with an already available object handle. More...
 
 vmemory (_Inout_ vmemory &&h) noexcept
 Move constructor. More...
 
virtual ~vmemory ()
 Frees the memory. More...
 
vmemoryoperator= (_Inout_ vmemory &&other) noexcept
 Move assignment. More...
 
void attach (_In_ HANDLE proc, _In_opt_ handle_type h) noexcept
 Sets a new memory handle for the class. More...
 
bool alloc (_In_ HANDLE hProcess, _In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, _In_ DWORD flAllocationType, _In_ DWORD flProtect) noexcept
 Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process. The function initializes the memory it allocates to zero. More...
 
- Public Member Functions inherited from winstd::handle< LPVOID, NULL >
 handle () noexcept
 Initializes a new class instance with the object handle set to INVAL.
 
 handle (_In_opt_ handle_type h) noexcept
 Initializes a new class instance with an already available object handle. More...
 
 handle (_Inout_ handle< handle_type, INVAL > &&h) noexcept
 Move constructor. More...
 
handle< handle_type, INVAL > & operator= (_In_opt_ handle_type h) noexcept
 Attaches already available object handle. More...
 
handle< handle_type, INVAL > & operator= (_Inout_ handle< handle_type, INVAL > &&h) noexcept
 Move assignment. More...
 
 operator handle_type () const
 Auto-typecasting operator. More...
 
handle_type *& operator* () const
 Returns the object handle value when the object handle is a pointer to a value (class, struct, etc.). More...
 
handle_typeoperator& ()
 Returns the object handle reference. More...
 
handle_type operator-> () const
 Provides object handle member access when the object handle is a pointer to a class or struct. More...
 
bool operator! () const
 Tests if the object handle is INVAL. More...
 
bool operator< (_In_opt_ handle_type h) const
 Is handle less than? More...
 
bool operator<= (_In_opt_ handle_type h) const
 Is handle less than or equal to? More...
 
bool operator>= (_In_opt_ handle_type h) const
 Is handle greater than or equal to? More...
 
bool operator> (_In_opt_ handle_type h) const
 Is handle greater than? More...
 
bool operator!= (_In_opt_ handle_type h) const
 Is handle not equal to? More...
 
bool operator== (_In_opt_ handle_type h) const
 Is handle equal to? More...
 
void attach (_In_opt_ handle_type h) noexcept
 Sets a new object handle for the class. More...
 
handle_type detach ()
 Dismisses the object handle from this class. More...
 
void free ()
 Destroys the object.
 

Protected Member Functions

void free_internal () noexcept override
 Frees the memory. More...
 
virtual void free_internal () noexcept=0
 Abstract member function that must be implemented by child classes to do the actual object destruction. More...
 

Protected Attributes

HANDLE m_proc
 Handle of memory's process.
 
- Protected Attributes inherited from winstd::handle< LPVOID, NULL >
handle_type m_h
 Object handle.
 

Additional Inherited Members

- Public Types inherited from winstd::handle< LPVOID, NULL >
typedef LPVOID handle_type
 Datatype of the object handle this template class handles.
 
- Static Public Attributes inherited from winstd::handle< LPVOID, NULL >
static const LPVOID invalid
 Invalid handle value.
 

Detailed Description

Memory in virtual address space of a process handle wrapper.

Constructor & Destructor Documentation

◆ vmemory() [1/2]

winstd::vmemory::vmemory ( _In_ handle_type  h,
_In_ HANDLE  proc 
)
inlinenoexcept

Initializes a new class instance with an already available object handle.

Parameters
[in]procHandle of process the memory belongs to
[in]hInitial object handle value

◆ vmemory() [2/2]

winstd::vmemory::vmemory ( _Inout_ vmemory &&  h)
inlinenoexcept

Move constructor.

Parameters
[in,out]hA rvalue reference of another object

◆ ~vmemory()

virtual winstd::vmemory::~vmemory ( )
inlinevirtual

Frees the memory.

See also
VirtualFreeEx function

Member Function Documentation

◆ alloc()

bool winstd::vmemory::alloc ( _In_ HANDLE  hProcess,
_In_opt_ LPVOID  lpAddress,
_In_ SIZE_T  dwSize,
_In_ DWORD  flAllocationType,
_In_ DWORD  flProtect 
)
inlinenoexcept

Reserves, commits, or changes the state of a region of memory within the virtual address space of a specified process. The function initializes the memory it allocates to zero.

See also
VirtualAllocEx function
Returns
  • true when succeeds;
  • false when fails. Use GetLastError() for failure reason.

◆ attach()

void winstd::vmemory::attach ( _In_ HANDLE  proc,
_In_opt_ handle_type  h 
)
inlinenoexcept

Sets a new memory handle for the class.

When the current object handle of the class is non-INVAL, the object is destroyed first.

Parameters
[in]procHandle of process the memory belongs to
[in]hInitial object handle value

◆ free_internal()

void winstd::vmemory::free_internal ( )
inlineoverrideprotectedvirtualnoexcept

Frees the memory.

See also
VirtualFreeEx function

Implements winstd::handle< LPVOID, NULL >.

◆ operator=()

vmemory & winstd::vmemory::operator= ( _Inout_ vmemory &&  other)
inlinenoexcept

Move assignment.

Parameters
[in,out]otherA rvalue reference of another object

The documentation for this class was generated from the following file: