+
+ if ( gs_useDirectX )
+ {
+ wxDisplayInfo& dpyInfo = (*gs_displays)[n];
+
+ LPDIRECTDRAW2& pDD2 = dpyInfo.m_pDD2;
+ if ( !pDD2 )
+ {
+ if ( !gs_DirectDrawCreate )
+ {
+ // what to do??
+ return;
+ }
+
+ IDirectDraw *pDD;
+ HRESULT hr = (*gs_DirectDrawCreate)(&dpyInfo.m_guid, &pDD, NULL);
+
+ if ( FAILED(hr) || !pDD )
+ {
+ // what to do??
+ wxLogApiError(_T("DirectDrawCreate"), hr);
+ }
+ else // got IDirectDraw, we want IDirectDraw2
+ {
+ hr = pDD->QueryInterface(wxIID_IDirectDraw2, (void **)&pDD2);
+ if ( FAILED(hr) || !pDD2 )
+ {
+ wxLogApiError(_T("IDirectDraw::QueryInterface(IDD2)"), hr);
+ }
+
+ pDD->Release();
+ }
+ }
+ //else: DirectDraw object corresponding to our display already exists
+
+ // increment its ref count to account for Release() in dtor
+ //
+ // NB: pDD2 will be only really Release()d when gs_displays is
+ // destroyed which is ok as we don't want to recreate DD objects
+ // all the time
+ pDD2->AddRef();
+ }
+}
+
+wxDisplay::~wxDisplay()
+{
+ wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
+
+ LPDIRECTDRAW2& pDD2 = dpyInfo.m_pDD2;
+ if ( pDD2 )
+ {
+ pDD2->Release();
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxDisplay simple accessors
+// ----------------------------------------------------------------------------
+
+bool wxDisplay::IsOk() const
+{
+ return m_index < GetCount() &&
+ (!gs_useDirectX || (*gs_displays)[m_index].m_pDD2);