Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
ReleaseDC (user32)
Releases a device context, freeing it for use by other applications.

C# Signature:

static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);

VB.NET Signature:

<DllImport("user32.dll")> _
Private Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

VB Signature:

Public Declare Function ReleaseDC Lib "user32.dll" _
         (ByVal hWnd As Long, _
          ByVal prmlngHDc As Long) As Long


The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common DC.

An application cannot use the ReleaseDC function to release a DC that was created by calling the CreateDC function; instead, it must use the DeleteDC function. ReleaseDC must be called from the same thread that called GetDC.

The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs.

Tips & Tricks:

Using managed DC functions for API's that require the DC work almost just as well as the API DC functions themselves.

For .NET Compact Framework, change user32.dll to coredll.dll.

Sample Code:

See TextOut or GetTextExtentPoint for a sample of using DC's in C# managed code.

Alternative Managed API:



ReleaseDC on MSDN

8-5-06 Update by Gabriel T. Sharp (

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version