1- using DirectN ;
2- using Files . App . ViewModels . Properties ;
1+ using Files . App . ViewModels . Properties ;
32using Microsoft . UI . Content ;
43using Microsoft . UI . Xaml ;
54using Microsoft . UI . Xaml . Hosting ;
65using System . Runtime . InteropServices ;
76using System . Text ;
87using Vanara . PInvoke ;
8+ using Windows . Win32 ;
9+ using Windows . Win32 . Graphics . Direct3D ;
10+ using Windows . Win32 . Graphics . Direct3D11 ;
11+ using Windows . Win32 . Graphics . Dxgi ;
12+ using Windows . Win32 . Graphics . DirectComposition ;
913using WinRT ;
1014using static Vanara . PInvoke . ShlwApi ;
1115using static Vanara . PInvoke . User32 ;
@@ -112,7 +116,7 @@ public void LoadPreview(UIElement presenter)
112116 _ = ChildWindowToXaml ( parent , presenter ) ;
113117 }
114118
115- private bool ChildWindowToXaml ( IntPtr parent , UIElement presenter )
119+ private unsafe bool ChildWindowToXaml ( IntPtr parent , UIElement presenter )
116120 {
117121 D3D_DRIVER_TYPE [ ] driverTypes =
118122 [
@@ -122,36 +126,36 @@ private bool ChildWindowToXaml(IntPtr parent, UIElement presenter)
122126
123127 ID3D11Device ? d3d11Device = null ;
124128 ID3D11DeviceContext ? d3d11DeviceContext = null ;
125- D3D_FEATURE_LEVEL featureLevelSupported ;
126129
127130 foreach ( var driveType in driverTypes )
128131 {
129- var hr = D3D11Functions . D3D11CreateDevice (
132+ var hr = PInvoke . D3D11CreateDevice (
130133 null ,
131134 driveType ,
132- IntPtr . Zero ,
133- ( uint ) D3D11_CREATE_DEVICE_FLAG . D3D11_CREATE_DEVICE_BGRA_SUPPORT ,
135+ new ( IntPtr . Zero ) ,
136+ D3D11_CREATE_DEVICE_FLAG . D3D11_CREATE_DEVICE_BGRA_SUPPORT ,
134137 null ,
135138 0 ,
136139 7 ,
137140 out d3d11Device ,
138- out featureLevelSupported ,
141+ null ,
139142 out d3d11DeviceContext ) ;
140143
141- if ( hr . IsSuccess )
144+ if ( hr . Succeeded )
142145 break ;
143146 }
144147
145148 if ( d3d11Device is null )
146149 return false ;
147150 IDXGIDevice dxgiDevice = ( IDXGIDevice ) d3d11Device ;
148- if ( Functions . DCompositionCreateDevice ( dxgiDevice , typeof ( IDCompositionDevice ) . GUID , out var compDevicePtr ) . IsError )
151+ if ( PInvoke . DCompositionCreateDevice ( dxgiDevice , typeof ( IDCompositionDevice ) . GUID , out var compDevicePtr ) . Failed )
149152 return false ;
150- IDCompositionDevice compDevice = ( IDCompositionDevice ) Marshal . GetObjectForIUnknown ( compDevicePtr ) ;
153+ IDCompositionDevice compDevice = ( IDCompositionDevice ) compDevicePtr ;
151154
152- if ( compDevice . CreateVisual ( out var childVisual ) . IsError ||
153- compDevice . CreateSurfaceFromHwnd ( hwnd . DangerousGetHandle ( ) , out var controlSurface ) . IsError ||
154- childVisual . SetContent ( controlSurface ) . IsError )
155+ compDevice . CreateVisual ( out var childVisual ) ;
156+ compDevice . CreateSurfaceFromHwnd ( new ( hwnd . DangerousGetHandle ( ) ) , out var controlSurface ) ;
157+ childVisual . SetContent ( controlSurface ) ;
158+ if ( childVisual is null || controlSurface is null )
155159 return false ;
156160
157161 var compositor = ElementCompositionPreview . GetElementVisual ( presenter ) . Compositor ;
@@ -169,7 +173,7 @@ private bool ChildWindowToXaml(IntPtr parent, UIElement presenter)
169173 Marshal . ReleaseComObject ( childVisual ) ;
170174 Marshal . ReleaseComObject ( controlSurface ) ;
171175 Marshal . ReleaseComObject ( compDevice ) ;
172- Marshal . Release ( compDevicePtr ) ;
176+ Marshal . ReleaseComObject ( compDevicePtr ) ;
173177 Marshal . ReleaseComObject ( dxgiDevice ) ;
174178 Marshal . ReleaseComObject ( d3d11Device ) ;
175179 Marshal . ReleaseComObject ( d3d11DeviceContext ) ;
0 commit comments