#pragma once #include #include #include #ifdef __cplusplus extern "C"{ #endif void* __RPC_USER midl_user_allocate(size_t size); void __RPC_USER midl_user_free(void* p); #ifdef __cplusplus } #endif /// /// Custom deleter for unique_ptr, that calls midl_user_free instead of delete. /// template struct midl_delete { // Empty constructor midl_delete(); // Deletion functor void operator()(T* ptr) const; }; template midl_delete::midl_delete() {} template void midl_delete::operator()(T* ptr) const { midl_user_free(ptr); } // Define the midl_ptr as parametrized unique_ptr. template using midl_ptr = std::unique_ptr>; // Allocators: template midl_ptr make_midl_ptr() { return midl_ptr((T*)midl_user_allocate(sizeof(T))); } template midl_ptr make_midl_ptr(ULONG count) { size_t totalSize = count * sizeof(T); return midl_ptr((T*)midl_user_allocate(totalSize)); }