CoGetMalloc function ole32

IMalloc? CoGetMalloc(
  1. int dwMemContext
)

Retrieves a pointer to the default OLE task memory allocator (which supports the system implementation of the IMalloc interface) so applications can call its methods to manage memory.

Throws a WindowsException on failure.

To learn more, see learn.microsoft.com/windows/win32/api/combaseapi/nf-combaseapi-cogetmalloc.

Implementation

IMalloc? CoGetMalloc(int dwMemContext) {
  final ppMalloc = adaptiveCalloc<VTablePointer>();
  final hr$ = HRESULT(_CoGetMalloc(dwMemContext, ppMalloc));
  if (hr$.isError) {
    free(ppMalloc);
    throw WindowsException(hr$);
  }
  final result$ = ppMalloc.value;
  free(ppMalloc);
  if (result$.isNull) return null;
  return .new(result$);
}