MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / GetData

Method GetData

PathCopyCopy/src/PathCopyCopyDataHandler.cpp:142–211  ·  view source on GitHub ↗

IDataObject::GetData Called by the shell when data is actually required. @param pformatetcIn Format descriptor for the format requested. @param pmedium Where to save the storage medium containing our data. @return S_OK if successful, otherwise an error code.

Source from the content-addressed store, hash-verified

140// @return S_OK if successful, otherwise an error code.
141//
142[[gsl::suppress(c.128)]]
143STDMETHODIMP CPathCopyCopyDataHandler::GetData(
144 FORMATETC *pformatetcIn,
145 STGMEDIUM *pmedium)
146{
147#ifdef PCC_DATA_HANDLER_LOGGING
148 GUID filg;
149 ::CoCreateGuid(&filg);
150 OLECHAR filn[256];
151 ::StringFromGUID2(filg, filn, 256);
152 std::wstringstream fils;
153 fils << L"C:\\" << filn << L".txt";
154 std::wstring filns = fils.str();
155 std::wofstream fil(ATL::CW2A(filns.c_str()));
156#endif // PCC_DATA_HANDLER_LOGGING
157
158 HRESULT hRes = E_INVALIDARG;
159 if (pformatetcIn != nullptr && pmedium != nullptr) {
160 try {
161 // Make sure we support this particular format. Since
162 // we only support one combination, we'll call QueryGetData.
163 hRes = this->QueryGetData(pformatetcIn);
164#ifdef PCC_DATA_HANDLER_LOGGING
165 fil << L"QueryGetDataResult: 0x" << std::hex << hRes << std::endl;
166#endif // PCC_DATA_HANDLER_LOGGING
167 if (SUCCEEDED(hRes)) {
168 // It's the format we support.
169
170 // First get the path of the file using the default plugin.
171 std::wstring newPath = PCC::Plugins::DefaultPlugin().GetPath(m_FileName);
172#ifdef PCC_DATA_HANDLER_LOGGING
173 fil << L"Filename: " << m_FileName << std::endl
174 << L"New path: " << newPath << std::endl;
175#endif // PCC_DATA_HANDLER_LOGGING
176
177 // Allocate an HGLOBAL to store the string.
178 const SIZE_T memSizeInBytes = (newPath.size() + 1) * sizeof(wchar_t);
179 StGlobalBlock globalBlock(GHND, memSizeInBytes);
180 if (globalBlock.Get() == nullptr) {
181#ifdef PCC_DATA_HANDLER_LOGGING
182 fil << L"GlobalAlloc failed!" << std::endl;
183#endif // PCC_DATA_HANDLER_LOGGING
184 hRes = STG_E_MEDIUMFULL;
185 } else {
186 // Lock the handle to access the memory and copy the path.
187 StGlobalLock rawBlock(globalBlock.Get());
188 void* pBlock = rawBlock.GetPtr();
189 if (pBlock == nullptr) {
190#ifdef PCC_DATA_HANDLER_LOGGING
191 fil << L"GlobalLock failed!" << std::endl;
192#endif // PCC_DATA_HANDLER_LOGGING
193 hRes = STG_E_MEDIUMFULL;
194 } else {
195 ::memcpy(pBlock, newPath.c_str(), memSizeInBytes);
196 hRes = S_OK;
197 }
198 }
199

Callers 1

InitializeMethod · 0.80

Calls 7

QueryGetDataMethod · 0.95
GetPtrMethod · 0.80
ReleaseMethod · 0.80
DefaultPluginClass · 0.50
GetPathMethod · 0.45
sizeMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected