I suspec this call pDC.CreateCompatibleDC(NULL); is failing. Check the return from this call first.