wailsapp/wails · error

Create compatible DC failed

Error message

Create compatible DC failed

What it means

Error "Create compatible DC failed" thrown in wailsapp/wails.

Source

Thrown at v3/pkg/w32/gdi32.go:159

		uintptr(hemfSrc),
		uintptr(unsafe.Pointer(lpszFile)))

	return HENHMETAFILE(ret)
}

func CreateBrushIndirect(lplb *LOGBRUSH) HBRUSH {
	ret, _, _ := procCreateBrushIndirect.Call(
		uintptr(unsafe.Pointer(lplb)))

	return HBRUSH(ret)
}

func CreateCompatibleDC(hdc HDC) HDC {
	ret, _, _ := procCreateCompatibleDC.Call(
		uintptr(hdc))

	if ret == 0 {
		panic("Create compatible DC failed")
	}

	return HDC(ret)
}

func CreateDC(lpszDriver, lpszDevice, lpszOutput *uint16, lpInitData *DEVMODE) HDC {
	ret, _, _ := procCreateDC.Call(
		uintptr(unsafe.Pointer(lpszDriver)),
		uintptr(unsafe.Pointer(lpszDevice)),
		uintptr(unsafe.Pointer(lpszOutput)),
		uintptr(unsafe.Pointer(lpInitData)))

	return HDC(ret)
}

func CreateDIBSection(hdc HDC, pbmi *BITMAPINFO, iUsage uint, ppvBits *unsafe.Pointer, hSection HANDLE, dwOffset uint) HBITMAP {
	ret, _, _ := procCreateDIBSection.Call(
		uintptr(hdc),

View on GitHub (pinned to 0e754b1b40)

Solutions

  1. Pass a valid source HDC to CreateCompatibleDC; passing 0 creates a DC compatible with the screen, but a garbage or already-deleted HDC causes failure.
  2. Check for GDI resource exhaustion: too many un-deleted DCs or bitmaps can make CreateCompatibleDC fail; ensure every created DC is released with DeleteDC.

When it happens

Trigger: Occurs when CreateCompatibleDC returns NULL, typically due to an invalid source DC handle or system GDI object exhaustion.

Common situations: See trigger scenarios.


AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15). Data as JSON: /api/errors/fadf93a297157544. Report an issue: GitHub.