Esempio n. 1
0
ZTuple ZDragClip_Win_DataObject::sAsTuple(IDataObject* iIDataObject)
	{
	ZTuple theTuple;
	ZDragClip_Win_DataObject* theDataObject;
	if (SUCCEEDED(iIDataObject->QueryInterface(ZDragClip_Win_DataObject::sIID, (void**)&theDataObject)))
		{
		theTuple = *theDataObject->GetTuple();
		theDataObject->Release();
		}
	else
		{
		vector<FORMATETC> filteredVector;
		::sFilterNonHGLOBAL(iIDataObject, filteredVector);

		for (vector<FORMATETC>::const_iterator i = filteredVector.begin();i != filteredVector.end(); ++i)
			{
			bool isString;
			string thePropertyName;
			if (ZDragClipManager::sGet()->LookupCLIPFORMAT((*i).cfFormat, thePropertyName, isString))
				{
				ZAssertStop(1, !thePropertyName.empty());
				FORMATETC theFORMATETC = *i;
				STGMEDIUM theSTGMEDIUM;
				HRESULT theHRESULT = iIDataObject->GetData(&theFORMATETC, &theSTGMEDIUM);
				if (SUCCEEDED(theHRESULT))
					{
					if (theSTGMEDIUM.tymed & TYMED_HGLOBAL)
						{
						void* globalPtr = ::GlobalLock(theSTGMEDIUM.hGlobal);
						// Special case text, to find and ignore the zero terminator, and to store a string.
						if (theFORMATETC.cfFormat == CF_TEXT)
							theTuple.SetString(thePropertyName, string(reinterpret_cast<char*>(globalPtr)));
						else
							theTuple.SetRaw(thePropertyName, globalPtr, ::GlobalSize(theSTGMEDIUM.hGlobal));

						::GlobalUnlock(theSTGMEDIUM.hGlobal);
						}
					::ReleaseStgMedium(&theSTGMEDIUM);
					}
				}
			}
		}
	return theTuple;
	}