Changeset 95836 in vbox for trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDEnumFormat.cpp
- Timestamp:
- Jul 26, 2022 4:16:02 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDEnumFormat.cpp
r95734 r95836 31 31 32 32 33 VBoxDnDEnumFormatEtc::VBoxDnDEnumFormatEtc(LPFORMATETC pFormatEtc, ULONG cFormats)33 VBoxDnDEnumFormatEtc::VBoxDnDEnumFormatEtc(LPFORMATETC pFormatEtc, ULONG uIdx, ULONG cToCopy, ULONG cTotal) 34 34 : m_cRefs(1) 35 35 , m_uIdxCur(0) … … 38 38 39 39 { 40 LogFlowFunc(("pFormatEtc=%p, cFormats=%RU32\n", pFormatEtc, cFormats)); 41 /** @todo r=bird: Use an init() function! */ 42 m_paFormatEtc = (LPFORMATETC)RTMemAllocZ(sizeof(*m_paFormatEtc) * cFormats); 43 if (m_paFormatEtc) 44 { 45 for (ULONG i = 0; i < cFormats; i++) 46 { 47 LogFlowFunc(("Format %RU32: cfFormat=%RI16, sFormat=%s, tyMed=%RU32, dwAspect=%RU32\n", 48 i, pFormatEtc[i].cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatEtc[i].cfFormat), 49 pFormatEtc[i].tymed, pFormatEtc[i].dwAspect)); 50 VBoxDnDEnumFormatEtc::CopyFormat(&m_paFormatEtc[i], &pFormatEtc[i]); 51 } 52 m_cFormats = cFormats; 53 } 54 else 55 Log(("Failed to allocate memory for %u formats!\n")); 40 int rc2 = Init(pFormatEtc, uIdx, cToCopy, cTotal); 41 AssertRC(rc2); 56 42 } 57 43 … … 74 60 } 75 61 62 /** 63 * Initializes the class by copying the required formats. 64 * 65 * @returns VBox status code. 66 * @param pFormatEtc Format Etc to use for initialization. 67 * @param uIdx Index (zero-based) of format 68 * @param cToCopy Number of formats \a pFormatEtc to copy, starting from \a uIdx. 69 * @param cTotal Number of total formats \a pFormatEtc holds. 70 */ 71 int VBoxDnDEnumFormatEtc::Init(LPFORMATETC pFormatEtc, ULONG uIdx, ULONG cToCopy, ULONG cTotal) 72 { 73 AssertPtrReturn(pFormatEtc, VERR_INVALID_POINTER); 74 AssertReturn(uIdx <= cTotal, VERR_INVALID_PARAMETER); 75 AssertReturn(uIdx + cToCopy <= cTotal, VERR_INVALID_PARAMETER); 76 /* cFormats can be 0. */ 77 78 if (!cToCopy) 79 return VINF_SUCCESS; 80 81 AssertReturn(m_paFormatEtc == NULL && m_cFormats == 0, VERR_WRONG_ORDER); 82 83 int rc = VINF_SUCCESS; 84 85 m_paFormatEtc = (LPFORMATETC)RTMemAllocZ(sizeof(FORMATETC) * cToCopy); 86 if (m_paFormatEtc) 87 { 88 for (ULONG i = 0; i < cToCopy; i++) 89 { 90 LPFORMATETC const pFormatCur = &pFormatEtc[uIdx + i]; 91 92 LogFlowFunc(("Format %RU32 (index %RU32): cfFormat=%RI16, sFormat=%s, tyMed=%RU32, dwAspect=%RU32\n", 93 i, uIdx + i, pFormatCur->cfFormat, VBoxDnDDataObject::ClipboardFormatToString(pFormatCur->cfFormat), 94 pFormatCur->tymed, pFormatCur->dwAspect)); 95 VBoxDnDEnumFormatEtc::CopyFormat(&m_paFormatEtc[i], pFormatCur); 96 } 97 98 m_cFormats = cToCopy; 99 } 100 else 101 rc = VERR_NO_MEMORY; 102 return rc; 103 } 104 76 105 /* 77 106 * IUnknown methods. … … 153 182 } 154 183 184 /** 185 * Copies a format etc from \a pSource to \a aDest (deep copy). 186 * 187 * @returns VBox status code. 188 * @param pDest Where to copy \a pSource to. 189 * @param pSource Source to copy. 190 */ 155 191 /* static */ 156 voidVBoxDnDEnumFormatEtc::CopyFormat(LPFORMATETC pDest, LPFORMATETC pSource)157 { 158 AssertPtrReturn Void(pDest);159 AssertPtrReturn Void(pSource);192 int VBoxDnDEnumFormatEtc::CopyFormat(LPFORMATETC pDest, LPFORMATETC pSource) 193 { 194 AssertPtrReturn(pDest , VERR_INVALID_POINTER); 195 AssertPtrReturn(pSource, VERR_INVALID_POINTER); 160 196 161 197 *pDest = *pSource; … … 164 200 { 165 201 pDest->ptd = (DVTARGETDEVICE*)CoTaskMemAlloc(sizeof(DVTARGETDEVICE)); 202 AssertPtrReturn(pDest->ptd, VERR_NO_MEMORY); 166 203 *(pDest->ptd) = *(pSource->ptd); 167 204 } 168 } 169 205 206 return VINF_SUCCESS; 207 } 208 209 /** 210 * Creates an IEnumFormatEtc interface from a given format etc structure. 211 * 212 * @returns HRESULT 213 * @param nNumFormats Number of formats to copy from \a pFormatEtc. 214 * @param pFormatEtc Format etc to use for creation. 215 * @param ppEnumFormatEtc Where to return the created IEnumFormatEtc interface on success. 216 */ 170 217 /* static */ 171 218 HRESULT VBoxDnDEnumFormatEtc::CreateEnumFormatEtc(UINT nNumFormats, LPFORMATETC pFormatEtc, IEnumFORMATETC **ppEnumFormatEtc) 172 219 { 173 AssertReturn(nNumFormats, E_INVALIDARG);220 /* cNumFormats can be 0. */ 174 221 AssertPtrReturn(pFormatEtc, E_INVALIDARG); 175 222 AssertPtrReturn(ppEnumFormatEtc, E_INVALIDARG); 176 223 177 224 #ifdef RT_EXCEPTIONS_ENABLED 178 try { *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, nNumFormats); } 225 try { *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, 226 0 /* uIdx */, nNumFormats /* cToCopy */, nNumFormats /* cTotal */); } 179 227 catch (std::bad_alloc &) 180 228 #else 181 *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, nNumFormats); 229 *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, 230 0 /* uIdx */, nNumFormats /* cToCopy */, nNumFormats /* cTotal */); 182 231 if (!*ppEnumFormatEtc) 183 232 #endif
Note:
See TracChangeset
for help on using the changeset viewer.