- wxClientDCImpl *srcDC = (wxClientDCImpl*)source->GetImpl();
- wxMemoryDCImpl *memDC = (wxMemoryDCImpl*)source;
+ wxWindowDCImpl *srcDC = wxDynamicCast(source->GetImpl(), wxWindowDCImpl);
+ wxCHECK_MSG( srcDC, false, "source must be a window DC" );
+
+ // FIXME: this cast is not always valid, see the code using m_isMemDC
+ wxMemoryDCImpl *memDC = wx_static_cast(wxMemoryDCImpl *, srcDC);