@@ -6,30 +6,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
66 return DefWindowProc (hWnd, message, wParam, lParam);
77}
88
9- typedef HRESULT (__stdcall* FuncPtrD3D11CreateDeviceAndSwapChain)(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType,
10- HMODULE Software, UINT Flags, CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion,
11- CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice,
12- D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext);
13-
149bool TestDX11Present ()
1510{
16- const auto hD3D11 = XRay::LoadModule (" d3d11.dll" );
17-
18- if (!hD3D11->exist ())
19- {
20- Log (" * DX11: failed to load d3d11.dll" );
21- return false ;
22- }
23-
24- auto pD3D11CreateDeviceAndSwapChain =
25- (FuncPtrD3D11CreateDeviceAndSwapChain)hD3D11->getProcAddress (" D3D11CreateDeviceAndSwapChain" );
26-
27- if (!pD3D11CreateDeviceAndSwapChain)
28- {
29- Log (" * DX11: failed to get address of D3D11CreateDeviceAndSwapChain" );
30- return false ;
31- }
32-
3311 // Register class
3412 WNDCLASSEX wcex;
3513 ZeroMemory (&wcex, sizeof (wcex));
@@ -47,16 +25,13 @@ bool TestDX11Present()
4725 HWND hWnd = CreateWindow (" TestDX11WindowClass" , " " , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
4826 CW_USEDEFAULT, CW_USEDEFAULT, NULL , NULL , NULL , NULL );
4927
50- DXGI_SWAP_CHAIN_DESC sd;
51-
5228 if (!hWnd)
5329 {
5430 Msg (" * DX11: failed to create window" );
5531 return false ;
5632 }
5733
58- HRESULT hr = E_FAIL;
59-
34+ DXGI_SWAP_CHAIN_DESC sd;
6035 ZeroMemory (&sd, sizeof (sd));
6136 sd.BufferCount = 1 ;
6237 sd.BufferDesc .Width = 800 ;
@@ -77,20 +52,18 @@ bool TestDX11Present()
7752 ID3D11DeviceContext* pContext = NULL ;
7853 IDXGISwapChain* pSwapChain = NULL ;
7954
80- hr = pD3D11CreateDeviceAndSwapChain (NULL , D3D_DRIVER_TYPE_HARDWARE, NULL , 0 , pFeatureLevels, 1 , D3D11_SDK_VERSION,
55+ HRESULT hr = D3D11CreateDeviceAndSwapChain (NULL , D3D_DRIVER_TYPE_HARDWARE, NULL , 0 , pFeatureLevels, 1 , D3D11_SDK_VERSION,
8156 &sd, &pSwapChain, &pd3dDevice, &FeatureLevel, &pContext);
8257
8358 if (FAILED (hr))
8459 Msg (" * D3D11: device creation failed with hr=0x%08x" , hr);
8560
86- if (pContext)
87- pContext->Release ();
88- if (pSwapChain)
89- pSwapChain->Release ();
90- if (pd3dDevice)
91- pd3dDevice->Release ();
61+ _RELEASE (pSwapChain);
62+ _RELEASE (pd3dDevice);
63+ _RELEASE (pContext);
9264
9365 DestroyWindow (hWnd);
66+ UnregisterClass (" TestDX11WindowClass" , GetModuleHandle (NULL ));
9467
9568 return SUCCEEDED (hr);
9669}
0 commit comments