winapi - Cast a ptr::null() to a Windows handle -


i'm trying use winapi crate create gui vst plugin. functions user32::setmenu need handles, of can null.

the following method called when plugin loaded:

fn open(&mut self, window: *mut c_void) {     unsafe {         let menu = user32::createmenu();         let sub_menu = user32::createmenu();         let hwnd: hwnd = window hwnd;         user32::setmenu(hwnd, menu);         let mut data = osstring::from("heee");         let raw = &mut data *mut _ lpwstr;         let mut menu_item = menuiteminfow {             cbsize: 0,             fmask: 0o0000_0020 | 0o0000_0040,             ftype: 0,             fstate: 0,             wid: menuitem_id,             hsubmenu: sub_menu,             hbmpchecked: ptr::null() hbitmap,             hbmpunchecked: ptr::null() hbitmap,             dwitemdata: 0,             dwtypedata: raw,             cch: 0,             hbmpitem: ptr::null() *mut _,         };         menu_item.cbsize = mem::size_of_val(&menu_item) u32;         user32::insertmenuitemw(menu, menuitem_id, 0, &menu_item);     }      self.open = true; } 

however, can't pass null handles:

hbmpchecked: ptr::null() hbitmap, 

i error message

hbmpchecked: ptr::null() hbitmap,              ^^^^^^^^^ cannot infer type `_` 

i can't find solution in docs of winapi/user32.

here how hbitmap defined in winapi:

type hbitmap = *mut hbitmap__; 

this makes hbitmap mutable raw pointer. ptr::null() returns const raw pointer. should use ptr::null_mut() instead, returns mutable raw pointer, compiler able infer correct type.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -