This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <Unknwn.h> | |
#include <exception> | |
template <typename T> struct COMPtrOut | |
{ | |
inline COMPtrOut() = delete; | |
inline COMPtrOut(const COMPtrOut&) = delete; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void* allocate_in_32bits(uint32_t start, uint32_t sz) { | |
if (!sz) return NULL; | |
MEMORY_BASIC_INFORMATION mbi = { 0 }; | |
char* min = (char*)start; | |
char* max = (char*)UINT32_MAX - sz; | |
while (min < max) { | |
if (!VirtualQuery(min, &mbi, sizeof mbi)) return NULL; | |
if (mbi.State == MEM_FREE && mbi.RegionSize > sz && mbi.BaseAddress) { | |
void* alloc = VirtualAlloc(mbi.BaseAddress, sz, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); | |
if ((uint64_t)alloc > UINT32_MAX) { VirtualFree(alloc, 0, MEM_RELEASE); return NULL; } |