@@ -131,8 +131,41 @@ pub fn create_surface(
131131 } ;
132132
133133 #[ cfg( target_os = "windows" ) ]
134- let ( raw_window_handle, raw_display_handle) =
135- { todo ! ( "implemnt windows raw window handle conversion" ) } ;
134+ let ( raw_window_handle, raw_display_handle) = {
135+ use raw_window_handle:: { Win32WindowHandle , WindowsDisplayHandle } ;
136+ use std:: num:: NonZeroIsize ;
137+ use windows:: Win32 :: Foundation :: HINSTANCE ;
138+ use windows:: Win32 :: System :: LibraryLoader :: GetModuleHandleW ;
139+
140+ if window_handle == 0 {
141+ return Err ( error:: ProcessingError :: InvalidWindowHandle ) ;
142+ }
143+
144+ // HWND is isize, so cast it
145+ let hwnd_isize = window_handle as isize ;
146+ let hwnd_nonzero = match NonZeroIsize :: new ( hwnd_isize) {
147+ Some ( nz) => nz,
148+ None => return Err ( error:: ProcessingError :: InvalidWindowHandle ) ,
149+ } ;
150+
151+ let mut window = Win32WindowHandle :: new ( hwnd_nonzero) ;
152+
153+ // VK_KHR_win32_surface requires hinstance *and* hwnd
154+ // SAFETY: GetModuleHandleW(NULL) is safe
155+ let hinstance = unsafe { GetModuleHandleW ( None ) }
156+ . map_err ( |_| error:: ProcessingError :: InvalidWindowHandle ) ?;
157+
158+ let hinstance_nonzero = NonZeroIsize :: new ( hinstance. 0 as isize )
159+ . ok_or ( error:: ProcessingError :: InvalidWindowHandle ) ?;
160+ window. hinstance = Some ( hinstance_nonzero) ;
161+
162+ let display = WindowsDisplayHandle :: new ( ) ;
163+
164+ (
165+ RawWindowHandle :: Win32 ( window) ,
166+ RawDisplayHandle :: Windows ( display) ,
167+ )
168+ } ;
136169
137170 #[ cfg( target_os = "linux" ) ]
138171 let ( raw_window_handle, raw_display_handle) =
0 commit comments