STDMETHODIMP QOleDataObject::GetDataHere( FORMATETC *pformatetc, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetc ); if ( hr != S_OK ) return hr; if ( pmedium->tymed != TYMED_HGLOBAL ) return DV_E_TYMED; if ( !pmedium->hGlobal ) return STG_E_MEDIUMFULL; HGLOBAL hGlobal = pmedium->hGlobal; uint size = GlobalSize( hGlobal ); int cf = pformatetc->cfFormat; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); if ( ba.size() > size ) return STG_E_MEDIUMFULL; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); return S_OK; } } return E_UNEXPECTED; }
STDMETHODIMP QOleDataObject::GetData( FORMATETC *pformatetcIn, STGMEDIUM *pmedium ) { // is data is in our format? HRESULT hr = QueryGetData( pformatetcIn ); if ( hr != S_OK ) return hr; int cf = pformatetcIn->cfFormat; pmedium->tymed = TYMED_HGLOBAL; QPtrList<QWindowsMime> all = QWindowsMime::all(); for ( QWindowsMime * c = all.first(); c ; c = all.next() ) { const char * mime = c->mimeFor( cf ); if ( mime && m_dragObj->provides( mime ) ) { QByteArray ba = m_dragObj->encodedData( mime ); ba = c->convertFromMime( ba, mime, cf ); HGLOBAL hGlobal = GlobalAlloc ( GMEM_MOVEABLE | GMEM_SHARE, ba.size() ); if ( !hGlobal ) return E_OUTOFMEMORY; memcpy ( GlobalLock ( hGlobal ), ba.data(), ba.size() ); GlobalUnlock ( hGlobal ); pmedium->hGlobal = hGlobal; pmedium->pUnkForRelease = NULL; return S_OK; } } return E_UNEXPECTED; }
STDMETHODIMP CTaskListData::GetData(FORMATETC *pFormat, STGMEDIUM *pMedium) { // OutputDebugString(_T("CTask::GetData\r\n")); pMedium->tymed = TYMED_NULL; pMedium->pUnkForRelease = NULL; pMedium->hGlobal = NULL; if(pMedium == NULL)return E_INVALIDARG; if(SUCCEEDED(QueryGetData(pFormat))) { if((pFormat->cfFormat == CF_TASK_ID) && pFormat->tymed == TYMED_HGLOBAL) { pFormat->cfFormat = CF_TASK_ID; pMedium->tymed = TYMED_HGLOBAL; pMedium->hGlobal = CoTaskMemAlloc(sizeof(unsigned __int64)); if(pMedium->hGlobal == NULL)return E_OUTOFMEMORY; *((unsigned __int64 *)pMedium->hGlobal) = m_id; return S_OK; } } return DV_E_FORMATETC; }
bool CIDataObject::GetData ( const wxDataFormat& rFormat, char* pzBuffer, ULONG ulLen ) { QueryGetData(rFormat); if (rFormat.GetType() == wxDF_INVALID) return false; ULONG ulSize = m_pDataObject->GetDataSize(rFormat); if (ulSize == 0) { // // It probably means that the method is just not implemented // return false; } if (rFormat.GetType() == wxDF_PRIVATE) { // // For custom formats, put the size with the data - alloc the // space for it // ulSize += sizeof(ULONG); } if (ulSize > ulLen) // not enough room to copy return false; // // Copy the data // GetDataHere( rFormat ,pzBuffer ,ulSize ); return true; } // end of CIDataObject::GetData
// get data functions STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium) { wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::GetData")); // is data is in our format? HRESULT hr = QueryGetData(pformatetcIn); if ( FAILED(hr) ) return hr; // for the bitmaps and metafiles we use the handles instead of global memory // to pass the data wxDataFormat format = (wxDataFormat::NativeFormat)pformatetcIn->cfFormat; format = HtmlFormatFixup(format); // is this system data? if ( GetSystemData(format, pmedium) ) { // pmedium is already filled with corresponding data, so we're ready. return S_OK; } switch ( format ) { case wxDF_BITMAP: pmedium->tymed = TYMED_GDI; break; case wxDF_ENHMETAFILE: pmedium->tymed = TYMED_ENHMF; break; #ifndef __WXWINCE__ case wxDF_METAFILE: pmedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, sizeof(METAFILEPICT)); if ( !pmedium->hGlobal ) { wxLogLastError(wxT("GlobalAlloc")); return E_OUTOFMEMORY; } pmedium->tymed = TYMED_MFPICT; break; #endif default: // alloc memory size_t size = m_pDataObject->GetDataSize(format); if ( !size ) { // it probably means that the method is just not implemented wxLogDebug(wxT("Invalid data size - can't be 0")); return DV_E_FORMATETC; } // we may need extra space for the buffer size size += m_pDataObject->GetBufferOffset( format ); HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, size); if ( hGlobal == NULL ) { wxLogLastError(wxT("GlobalAlloc")); return E_OUTOFMEMORY; } // copy data pmedium->tymed = TYMED_HGLOBAL; pmedium->hGlobal = hGlobal; } pmedium->pUnkForRelease = NULL; // do copy the data hr = GetDataHere(pformatetcIn, pmedium); if ( FAILED(hr) ) { // free resources we allocated if ( pmedium->tymed & (TYMED_HGLOBAL | TYMED_MFPICT) ) { GlobalFree(pmedium->hGlobal); } return hr; } return S_OK; }