Windows API Heap Allocation

use windows::Win32::System::Memory::{HeapAlloc,HEAP_FLAGS};

fn main() {
    let base_address = unsafe {HeapAlloc(None, HEAP_FLAGS(0), 100)};
    if base_address.is_null() {
            println!("HeapAlloc failed.");
    } else {
            println!("BaseAddress: 0x{:?}", base_address);
    }
}

the program doesn't print anything on the console, it just exit why ?

Just guessing: The HeapAlloc doc says the first param should be as follows, but you've passed None which I assume is a null handle.

A handle to the heap from which the memory will be allocated. This handle is returned by the HeapCreate or GetProcessHeap function.

1 Like
  • Program behaving weird
  • Uses unsafe without a safety comment justifying why it's fine

I bet I know where to look :slight_smile:

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.