Example #1
0
        /// <summary>
        /// Releases, decommits, or releases and decommits a region of memory within the virtual address space of a specified process.
        /// </summary>
        /// <param name="hProcess">Handle to the process in which memory will be freed.</param>
        /// <param name="dwAddress">A pointer to the starting address of the region of memory to be freed. </param>
        /// <param name="nSize">
        /// The size of the region of memory to free, in bytes.
        ///
        /// If the dwFreeType parameter is MEM_RELEASE, dwSize must be 0 (zero). The function frees the entire region that is reserved in the initial allocation call to VirtualAllocEx.</param>
        /// <param name="dwFreeType">The type of free operation.  See <see cref="MemoryFreeType"/>.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        public static bool FreeMemory(IntPtr hProcess, uint dwAddress, int nSize, uint dwFreeType)
        {
            if (dwFreeType == MemoryFreeType.MEM_RELEASE)
            {
                nSize = 0;
            }

            return(Imports.VirtualFreeEx(hProcess, dwAddress, nSize, dwFreeType));
        }