IDXGISurface1::GetDC method (dxgi.h)

Returns a device context (DC) that allows you to render to a Microsoft DirectX Graphics Infrastructure (DXGI) surface using Windows Graphics Device Interface (GDI).


        BOOL Discard,
  [out] HDC  *phdc



Type: BOOL

A Boolean value that specifies whether to preserve Direct3D contents in the GDI DC. TRUE directs the runtime not to preserve Direct3D contents in the GDI DC; that is, the runtime discards the Direct3D contents. FALSE guarantees that Direct3D contents are available in the GDI DC.

[out] phdc

Type: HDC*

A pointer to an HDC handle that represents the current device context for GDI rendering.

Return value


Returns S_OK if successful; otherwise, an error code.


This method is not supported by DXGI 1.0, which shipped in Windows Vista and Windows Server 2008. DXGI 1.1 support is required, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista with Service Pack 2 (SP2) (KB 971644) and Windows Server 2008 (KB 971512).

After you use the GetDC method to retrieve a DC, you can render to the DXGI surface by using GDI.
The GetDC method readies the surface for GDI rendering and allows inter-operation between DXGI and GDI technologies.

Keep the following in mind when using this method:

You can also call GetDC on the back buffer at index 0 of a swap chain by obtaining an IDXGISurface1 from the swap chain. The following code illustrates the process.

IDXGISwapChain* g_pSwapChain = NULL;
IDXGISurface1* g_pSurface1 = NULL;
//Setup the device and and swapchain
g_pSwapChain->GetBuffer(0, __uuidof(IDXGISurface1), (void**) &g_pSurface1);
g_pSurface1->GetDC( FALSE, &g_hDC );
//Draw on the DC using GDI
//When finish drawing release the DC
g_pSurface1->ReleaseDC( NULL );


Minimum supported client Windows 7 [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2 [desktop apps | UWP apps]
Target Platform Windows
Header dxgi.h
Library DXGI.lib

See also

DXGI Interfaces