VirtualBox

Changeset 95734 in vbox for trunk/src/VBox/Additions/WINNT


Ignore:
Timestamp:
Jul 19, 2022 9:50:40 PM (3 years ago)
Author:
vboxsync
Message:

VBoxTray/DnD: Make the code build w/o exceptions enabled. bugref:10261

Location:
trunk/src/VBox/Additions/WINNT/VBoxTray
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnD.cpp

    r93299 r95734  
    673673
    674674#ifdef VBOX_WITH_DRAG_AND_DROP_GH
     675
    675676/**
    676677 * Registers this proxy window as a local drop target.
     
    683684        return VINF_SUCCESS;
    684685
    685     int rc;
    686     try
    687     {
    688         m_pDropTarget = new VBoxDnDDropTarget(this /* pParent */);
    689         HRESULT hr = CoLockObjectExternal(m_pDropTarget, TRUE /* fLock */,
    690                                           FALSE /* fLastUnlockReleases */);
    691         if (SUCCEEDED(hr))
    692             hr = RegisterDragDrop(m_hWnd, m_pDropTarget);
    693 
    694         if (FAILED(hr))
    695         {
    696             if (hr != DRAGDROP_E_INVALIDHWND) /* Could be because the DnD host service is not available. */
    697                 LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hr));
    698             rc = VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
    699         }
    700         else
    701         {
    702             rc = VINF_SUCCESS;
    703         }
    704     }
    705     catch (std::bad_alloc)
    706     {
    707         rc = VERR_NO_MEMORY;
    708     }
    709 
    710     LogFlowFuncLeaveRC(rc);
    711     return rc;
     686# ifdef RT_EXCEPTIONS_ENABLED
     687    try { m_pDropTarget = new VBoxDnDDropTarget(this /* pParent */); }
     688    catch (std::bad_alloc &)
     689# else
     690    m_pDropTarget = new VBoxDnDDropTarget(this /* pParent */);
     691    if (!m_pDropTarget)
     692# endif
     693    {
     694        LogFunc(("VERR_NO_MEMORY!\n"));
     695        return VERR_NO_MEMORY;
     696    }
     697
     698    HRESULT hrc = CoLockObjectExternal(m_pDropTarget, TRUE /* fLock */, FALSE /* fLastUnlockReleases */);
     699    if (SUCCEEDED(hrc))
     700    {
     701        hrc = RegisterDragDrop(m_hWnd, m_pDropTarget);
     702        if (SUCCEEDED(hrc))
     703        {
     704            LogFlowFuncLeaveRC(VINF_SUCCESS);
     705            return VINF_SUCCESS;
     706        }
     707    }
     708    if (hrc != DRAGDROP_E_INVALIDHWND) /* Could be because the DnD host service is not available. */
     709        LogRel(("DnD: Creating drop target failed with hr=%Rhrc\n", hrc));
     710    LogFlowFuncLeaveRC(VERR_NOT_SUPPORTED);
     711    return VERR_NOT_SUPPORTED; /* Report back DnD as not being supported. */
    712712}
    713713
     
    741741    return rc;
    742742}
     743
    743744#endif /* VBOX_WITH_DRAG_AND_DROP_GH */
    744745
     
    829830        return rc;
    830831
     832    /* Save all allowed actions. */
     833    this->m_lstActionsAllowed = a_fDndLstActionsAllowed;
     834
     835    /*
     836     * Check if reported formats from host are compatible with this client.
     837     */
     838    size_t cFormatsSup    = this->m_lstFmtSup.size();
     839    ULONG  cFormatsActive = 0;
     840
     841    LPFORMATETC paFormatEtc = (LPFORMATETC)RTMemTmpAllocZ(sizeof(paFormatEtc[0]) * cFormatsSup);
     842    AssertReturn(paFormatEtc, VERR_NO_TMP_MEMORY);
     843
     844    LPSTGMEDIUM paStgMeds   = (LPSTGMEDIUM)RTMemTmpAllocZ(sizeof(paStgMeds[0]) * cFormatsSup);
     845    AssertReturnStmt(paFormatEtc, RTMemTmpFree(paFormatEtc), VERR_NO_TMP_MEMORY);
     846
     847    LogRel2(("DnD: Reported formats:\n"));
     848    for (size_t i = 0; i < a_lstFormats.size(); i++)
     849    {
     850        bool fSupported = false;
     851        for (size_t a = 0; a < this->m_lstFmtSup.size(); a++)
     852        {
     853            const char *pszFormat = a_lstFormats.at(i).c_str();
     854            LogFlowThisFunc(("\t\"%s\" <=> \"%s\"\n", this->m_lstFmtSup.at(a).c_str(), pszFormat));
     855
     856            fSupported = RTStrICmp(this->m_lstFmtSup.at(a).c_str(), pszFormat) == 0;
     857            if (fSupported)
     858            {
     859                this->m_lstFmtActive.append(a_lstFormats.at(i));
     860
     861                /** @todo Put this into a \#define / struct. */
     862                if (!RTStrICmp(pszFormat, "text/uri-list"))
     863                {
     864                    paFormatEtc[cFormatsActive].cfFormat = CF_HDROP;
     865                    paFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
     866                    paFormatEtc[cFormatsActive].lindex   = -1;
     867                    paFormatEtc[cFormatsActive].tymed    = TYMED_HGLOBAL;
     868
     869                    paStgMeds  [cFormatsActive].tymed    = TYMED_HGLOBAL;
     870                    cFormatsActive++;
     871                }
     872                else if (   !RTStrICmp(pszFormat, "text/plain")
     873                         || !RTStrICmp(pszFormat, "text/html")
     874                         || !RTStrICmp(pszFormat, "text/plain;charset=utf-8")
     875                         || !RTStrICmp(pszFormat, "text/plain;charset=utf-16")
     876                         || !RTStrICmp(pszFormat, "text/plain")
     877                         || !RTStrICmp(pszFormat, "text/richtext")
     878                         || !RTStrICmp(pszFormat, "UTF8_STRING")
     879                         || !RTStrICmp(pszFormat, "TEXT")
     880                         || !RTStrICmp(pszFormat, "STRING"))
     881                {
     882                    paFormatEtc[cFormatsActive].cfFormat = CF_TEXT;
     883                    paFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
     884                    paFormatEtc[cFormatsActive].lindex   = -1;
     885                    paFormatEtc[cFormatsActive].tymed    = TYMED_HGLOBAL;
     886
     887                    paStgMeds  [cFormatsActive].tymed    = TYMED_HGLOBAL;
     888                    cFormatsActive++;
     889                }
     890                else /* Should never happen. */
     891                    AssertReleaseMsgFailedBreak(("Format specification for '%s' not implemented\n", pszFormat));
     892                break;
     893            }
     894        }
     895
     896        LogRel2(("DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported));
     897    }
     898
     899    /*
     900     * Warn in the log if this guest does not accept anything.
     901     */
     902    Assert(cFormatsActive <= cFormatsSup);
     903    if (cFormatsActive)
     904    {
     905        LogRel2(("DnD: %RU32 supported formats found:\n", cFormatsActive));
     906        for (size_t i = 0; i < cFormatsActive; i++)
     907            LogRel2(("DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str()));
     908    }
     909    else
     910        LogRel(("DnD: Warning: No supported drag and drop formats on the guest found!\n"));
     911
     912    /*
     913     * Prepare the startup info for DoDragDrop().
     914     */
     915
     916    /* Translate our drop actions into allowed Windows drop effects. */
     917    m_startupInfo.dwOKEffects = DROPEFFECT_NONE;
     918    if (a_fDndLstActionsAllowed)
     919    {
     920        if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_COPY)
     921            m_startupInfo.dwOKEffects |= DROPEFFECT_COPY;
     922        if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_MOVE)
     923            m_startupInfo.dwOKEffects |= DROPEFFECT_MOVE;
     924        if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_LINK)
     925            m_startupInfo.dwOKEffects |= DROPEFFECT_LINK;
     926    }
     927
     928    LogRel2(("DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects));
     929
     930#ifdef RT_EXCEPTIONS_ENABLED
    831931    try
    832932    {
    833         /* Save all allowed actions. */
    834         this->m_lstActionsAllowed = a_fDndLstActionsAllowed;
    835 
    836         /*
    837          * Check if reported formats from host are compatible with this client.
    838          */
    839         size_t cFormatsSup    = this->m_lstFmtSup.size();
    840         ULONG  cFormatsActive = 0;
    841 
    842         LPFORMATETC pFormatEtc = new FORMATETC[cFormatsSup];
    843         RT_BZERO(pFormatEtc, sizeof(FORMATETC) * cFormatsSup);
    844 
    845         LPSTGMEDIUM pStgMeds   = new STGMEDIUM[cFormatsSup];
    846         RT_BZERO(pStgMeds, sizeof(STGMEDIUM) * cFormatsSup);
    847 
    848         LogRel2(("DnD: Reported formats:\n"));
    849         for (size_t i = 0; i < a_lstFormats.size(); i++)
    850         {
    851             bool fSupported = false;
    852             for (size_t a = 0; a < this->m_lstFmtSup.size(); a++)
    853             {
    854                 const char *pszFormat = a_lstFormats.at(i).c_str();
    855                 LogFlowThisFunc(("\t\"%s\" <=> \"%s\"\n", this->m_lstFmtSup.at(a).c_str(), pszFormat));
    856 
    857                 fSupported = RTStrICmp(this->m_lstFmtSup.at(a).c_str(), pszFormat) == 0;
    858                 if (fSupported)
    859                 {
    860                     this->m_lstFmtActive.append(a_lstFormats.at(i));
    861 
    862                     /** @todo Put this into a \#define / struct. */
    863                     if (!RTStrICmp(pszFormat, "text/uri-list"))
    864                     {
    865                         pFormatEtc[cFormatsActive].cfFormat = CF_HDROP;
    866                         pFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
    867                         pFormatEtc[cFormatsActive].lindex   = -1;
    868                         pFormatEtc[cFormatsActive].tymed    = TYMED_HGLOBAL;
    869 
    870                         pStgMeds  [cFormatsActive].tymed    = TYMED_HGLOBAL;
    871                         cFormatsActive++;
    872                     }
    873                     else if (   !RTStrICmp(pszFormat, "text/plain")
    874                              || !RTStrICmp(pszFormat, "text/html")
    875                              || !RTStrICmp(pszFormat, "text/plain;charset=utf-8")
    876                              || !RTStrICmp(pszFormat, "text/plain;charset=utf-16")
    877                              || !RTStrICmp(pszFormat, "text/plain")
    878                              || !RTStrICmp(pszFormat, "text/richtext")
    879                              || !RTStrICmp(pszFormat, "UTF8_STRING")
    880                              || !RTStrICmp(pszFormat, "TEXT")
    881                              || !RTStrICmp(pszFormat, "STRING"))
    882                     {
    883                         pFormatEtc[cFormatsActive].cfFormat = CF_TEXT;
    884                         pFormatEtc[cFormatsActive].dwAspect = DVASPECT_CONTENT;
    885                         pFormatEtc[cFormatsActive].lindex   = -1;
    886                         pFormatEtc[cFormatsActive].tymed    = TYMED_HGLOBAL;
    887 
    888                         pStgMeds  [cFormatsActive].tymed    = TYMED_HGLOBAL;
    889                         cFormatsActive++;
    890                     }
    891                     else /* Should never happen. */
    892                         AssertReleaseMsgFailedBreak(("Format specification for '%s' not implemented\n", pszFormat));
    893                     break;
    894                 }
    895             }
    896 
    897             LogRel2(("DnD: \t%s: %RTbool\n", a_lstFormats.at(i).c_str(), fSupported));
    898         }
    899 
    900         /*
    901          * Warn in the log if this guest does not accept anything.
    902          */
    903         Assert(cFormatsActive <= cFormatsSup);
    904         if (cFormatsActive)
    905         {
    906             LogRel2(("DnD: %RU32 supported formats found:\n", cFormatsActive));
    907             for (size_t i = 0; i < cFormatsActive; i++)
    908                 LogRel2(("DnD: \t%s\n", this->m_lstFmtActive.at(i).c_str()));
    909         }
    910         else
    911             LogRel(("DnD: Warning: No supported drag and drop formats on the guest found!\n"));
    912 
    913         /*
    914          * Prepare the startup info for DoDragDrop().
    915          */
    916 
    917         /* Translate our drop actions into allowed Windows drop effects. */
    918         m_startupInfo.dwOKEffects = DROPEFFECT_NONE;
    919         if (a_fDndLstActionsAllowed)
    920         {
    921             if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_COPY)
    922                 m_startupInfo.dwOKEffects |= DROPEFFECT_COPY;
    923             if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_MOVE)
    924                 m_startupInfo.dwOKEffects |= DROPEFFECT_MOVE;
    925             if (a_fDndLstActionsAllowed & VBOX_DND_ACTION_LINK)
    926                 m_startupInfo.dwOKEffects |= DROPEFFECT_LINK;
    927         }
    928 
    929         LogRel2(("DnD: Supported drop actions: 0x%x\n", m_startupInfo.dwOKEffects));
    930 
    931933        m_startupInfo.pDropSource = new VBoxDnDDropSource(this);
    932         m_startupInfo.pDataObject = new VBoxDnDDataObject(pFormatEtc, pStgMeds, cFormatsActive);
    933 
    934         if (pFormatEtc)
    935             delete pFormatEtc;
    936         if (pStgMeds)
    937             delete pStgMeds;
    938     }
    939     catch (std::bad_alloc)
    940     {
     934        m_startupInfo.pDataObject = new VBoxDnDDataObject(paFormatEtc, paStgMeds, cFormatsActive);
     935    }
     936    catch (std::bad_alloc &)
     937#else
     938    m_startupInfo.pDropSource = new VBoxDnDDropSource(this);
     939    m_startupInfo.pDataObject = new VBoxDnDDataObject(paFormatEtc, paStgMeds, cFormatsActive);
     940    if (!m_startupInfo.pDropSource || !m_startupInfo.pDataObject)
     941#endif
     942    {
     943        LogFunc(("VERR_NO_MEMORY!"));
    941944        rc = VERR_NO_MEMORY;
    942945    }
     946
     947    RTMemTmpFree(paFormatEtc);
     948    RTMemTmpFree(paStgMeds);
    943949
    944950    if (RT_SUCCESS(rc))
     
    17451751         * only support one window at a time. */
    17461752        VBoxDnDWnd *pWnd = NULL;
    1747         try
    1748         {
    1749             pWnd = new VBoxDnDWnd();
     1753#ifdef RT_EXCEPTIONS_ENABLED
     1754        try { pWnd = new VBoxDnDWnd(); }
     1755        catch (std::bad_alloc &)
     1756#else
     1757        pWnd = new VBoxDnDWnd();
     1758        if (!pWnd)
     1759#endif
     1760        {
     1761            rc = VERR_NO_MEMORY;
     1762        }
     1763        if (RT_SUCCESS(rc))
     1764        {
    17501765            rc = pWnd->Initialize(pCtx);
    1751 
    1752             /* Add proxy window to our proxy windows list. */
    17531766            if (RT_SUCCESS(rc))
    1754                 pCtx->lstWnd.append(pWnd);
    1755         }
    1756         catch (std::bad_alloc)
    1757         {
    1758             rc = VERR_NO_MEMORY;
     1767            {
     1768                /* Add proxy window to our proxy windows list. */
     1769#ifdef RT_EXCEPTIONS_ENABLED
     1770                try { pCtx->lstWnd.append(pWnd); /** @todo the list implementation sucks wrt exception handling. */ }
     1771                catch (std::bad_alloc &)
     1772                {
     1773                    delete pWnd;
     1774                    rc = VERR_NO_MEMORY;
     1775                }
     1776#else
     1777                pCtx->lstWnd.append(pWnd); /** @todo the list implementation sucks wrt exception handling. */
     1778#endif
     1779            }
     1780            else
     1781                delete pWnd;
    17591782        }
    17601783    }
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDDataObject.cpp

    r93115 r95734  
    4242
    4343VBoxDnDDataObject::VBoxDnDDataObject(LPFORMATETC pFormatEtc, LPSTGMEDIUM pStgMed, ULONG cFormats)
    44     : m_enmStatus(Status_Uninitialized),
    45       m_cRefs(1),
    46       m_cFormats(0),
    47       m_pvData(NULL),
    48       m_cbData(0)
    49 {
    50     HRESULT hr;
    51 
     44    : m_enmStatus(Status_Uninitialized)
     45    , m_cRefs(1)
     46    , m_cFormats(0)
     47    , m_paFormatEtc(0)
     48    , m_paStgMedium(0)
     49    , m_EvtDropped(NIL_RTSEMEVENT)
     50    , m_pvData(NULL)
     51    , m_cbData(0)
     52{
     53
     54    /*
     55     * Allocate arrays for format related stuff.
     56     */
     57    /** @todo r=bird: Use an init function */
     58    int   rc = VERR_NO_MEMORY;
    5259    ULONG cFixedFormats = 1;
    5360    ULONG cAllFormats   = cFormats + cFixedFormats;
    54 
    55     try
    56     {
    57         m_paFormatEtc = new FORMATETC[cAllFormats];
    58         RT_BZERO(m_paFormatEtc, sizeof(FORMATETC) * cAllFormats);
    59         m_paStgMedium = new STGMEDIUM[cAllFormats];
    60         RT_BZERO(m_paStgMedium, sizeof(STGMEDIUM) * cAllFormats);
    61 
    62         /*
    63          * Registration of dynamic formats needed?
    64          */
    65         LogFlowFunc(("%RU32 dynamic formats\n", cFormats));
    66         if (cFormats)
     61    m_paFormatEtc = (LPFORMATETC)RTMemAllocZ(sizeof(m_paFormatEtc[0]) * cAllFormats);
     62    if (m_paFormatEtc)
     63    {
     64        m_paStgMedium = (LPSTGMEDIUM)RTMemAllocZ(sizeof(m_paStgMedium[0]) * cAllFormats);
     65        if (m_EvtDropped)
    6766        {
    68             AssertPtr(pFormatEtc);
    69             AssertPtr(pStgMed);
    70 
    71             for (ULONG i = 0; i < cFormats; i++)
     67
     68            /*
     69             * Registration of dynamic formats needed?
     70             */
     71            LogFlowFunc(("%RU32 dynamic formats\n", cFormats));
     72            if (cFormats)
    7273            {
    73                 LogFlowFunc(("Format %RU32: cfFormat=%RI16, tyMed=%RU32, dwAspect=%RU32\n",
    74                              i, pFormatEtc[i].cfFormat, pFormatEtc[i].tymed, pFormatEtc[i].dwAspect));
    75                 m_paFormatEtc[i] = pFormatEtc[i];
    76                 m_paStgMedium[i] = pStgMed[i];
     74                AssertPtr(pFormatEtc);
     75                AssertPtr(pStgMed);
     76
     77                for (ULONG i = 0; i < cFormats; i++)
     78                {
     79                    LogFlowFunc(("Format %RU32: cfFormat=%RI16, tyMed=%RU32, dwAspect=%RU32\n",
     80                                 i, pFormatEtc[i].cfFormat, pFormatEtc[i].tymed, pFormatEtc[i].dwAspect));
     81                    m_paFormatEtc[i] = pFormatEtc[i];
     82                    m_paStgMedium[i] = pStgMed[i];
     83                }
    7784            }
     85
     86            rc = RTSemEventCreate(&m_EvtDropped);
     87            AssertRCStmt(rc, m_EvtDropped = NIL_RTSEMEVENT);
     88
     89            /*
     90             * Register fixed formats.
     91             */
     92#if 0
     93            /* CF_HDROP. */
     94            RegisterFormat(&mpFormatEtc[cFormats], CF_HDROP);
     95            mpStgMedium[cFormats++].tymed = TYMED_HGLOBAL;
     96
     97            /* IStream. */
     98            RegisterFormat(&mpFormatEtc[cFormats++],
     99                           RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR));
     100            RegisterFormat(&mpFormatEtc[cFormats++],
     101                           RegisterClipboardFormat(CFSTR_FILECONTENTS),
     102                           TYMED_ISTREAM, 0 /* lIndex */);
     103
     104            /* Required for e.g. Windows Media Player. */
     105            RegisterFormat(&mpFormatEtc[cFormats++],
     106                           RegisterClipboardFormat(CFSTR_FILENAME));
     107            RegisterFormat(&mpFormatEtc[cFormats++],
     108                           RegisterClipboardFormat(CFSTR_FILENAMEW));
     109            RegisterFormat(&mpFormatEtc[cFormats++],
     110                           RegisterClipboardFormat(CFSTR_SHELLIDLIST));
     111            RegisterFormat(&mpFormatEtc[cFormats++],
     112                           RegisterClipboardFormat(CFSTR_SHELLIDLISTOFFSET));
     113#endif
     114            m_cFormats  = cFormats;
     115            m_enmStatus = Status_Initialized;
    78116        }
    79 
    80         hr = S_OK;
    81     }
    82     catch (std::bad_alloc &)
    83     {
    84         hr = E_OUTOFMEMORY;
    85     }
    86 
    87     if (SUCCEEDED(hr))
    88     {
    89         int rc2 = RTSemEventCreate(&m_EvtDropped);
    90         AssertRC(rc2);
    91 
    92         /*
    93          * Register fixed formats.
    94          */
    95 #if 0
    96         /* CF_HDROP. */
    97         RegisterFormat(&mpFormatEtc[cFormats], CF_HDROP);
    98         mpStgMedium[cFormats++].tymed = TYMED_HGLOBAL;
    99 
    100         /* IStream. */
    101         RegisterFormat(&mpFormatEtc[cFormats++],
    102                        RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR));
    103         RegisterFormat(&mpFormatEtc[cFormats++],
    104                        RegisterClipboardFormat(CFSTR_FILECONTENTS),
    105                        TYMED_ISTREAM, 0 /* lIndex */);
    106 
    107         /* Required for e.g. Windows Media Player. */
    108         RegisterFormat(&mpFormatEtc[cFormats++],
    109                        RegisterClipboardFormat(CFSTR_FILENAME));
    110         RegisterFormat(&mpFormatEtc[cFormats++],
    111                        RegisterClipboardFormat(CFSTR_FILENAMEW));
    112         RegisterFormat(&mpFormatEtc[cFormats++],
    113                        RegisterClipboardFormat(CFSTR_SHELLIDLIST));
    114         RegisterFormat(&mpFormatEtc[cFormats++],
    115                        RegisterClipboardFormat(CFSTR_SHELLIDLISTOFFSET));
    116 #endif
    117         m_cFormats = cFormats;
    118         m_enmStatus   = Status_Initialized;
    119     }
    120 
    121     LogFlowFunc(("cFormats=%RU32, hr=%Rhrc\n", cFormats, hr));
     117    }
     118    LogFlowFunc(("cFormats=%RU32 - %Rrc!\n", cFormats, rc));
    122119}
    123120
     
    125122{
    126123    if (m_paFormatEtc)
    127         delete[] m_paFormatEtc;
     124    {
     125        RTMemFree(m_paFormatEtc);
     126        m_paFormatEtc = NULL;
     127    }
    128128
    129129    if (m_paStgMedium)
    130         delete[] m_paStgMedium;
     130    {
     131        RTMemFree(m_paStgMedium);
     132        m_paStgMedium = NULL;
     133    }
    131134
    132135    if (m_pvData)
     136    {
    133137        RTMemFree(m_pvData);
     138        m_pvData = NULL;
     139    }
    134140
    135141    LogFlowFunc(("mRefCount=%RI32\n", m_cRefs));
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDnDEnumFormat.cpp

    r93115 r95734  
    3232
    3333VBoxDnDEnumFormatEtc::VBoxDnDEnumFormatEtc(LPFORMATETC pFormatEtc, ULONG cFormats)
    34     : m_cRefs(1),
    35       m_uIdxCur(0)
     34    : m_cRefs(1)
     35    , m_uIdxCur(0)
     36    , m_cFormats(0)
     37    , m_paFormatEtc(NULL)
     38
    3639{
    37     HRESULT hr;
    38 
    39     try
     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)
    4044    {
    41         LogFlowFunc(("pFormatEtc=%p, cFormats=%RU32\n", pFormatEtc, cFormats));
    42         m_paFormatEtc  = new FORMATETC[cFormats];
    43 
    4445        for (ULONG i = 0; i < cFormats; i++)
    4546        {
     
    4950            VBoxDnDEnumFormatEtc::CopyFormat(&m_paFormatEtc[i], &pFormatEtc[i]);
    5051        }
    51 
    5252        m_cFormats = cFormats;
    53         hr = S_OK;
    5453    }
    55     catch (std::bad_alloc &)
    56     {
    57         hr = E_OUTOFMEMORY;
    58     }
    59 
    60     LogFlowFunc(("hr=%Rhrc\n", hr));
     54    else
     55        Log(("Failed to allocate memory for %u formats!\n"));
    6156}
    6257
     
    6661    {
    6762        for (ULONG i = 0; i < m_cFormats; i++)
    68         {
    69             if(m_paFormatEtc[i].ptd)
     63            if (m_paFormatEtc[i].ptd)
     64            {
    7065                CoTaskMemFree(m_paFormatEtc[i].ptd);
    71         }
     66                m_paFormatEtc[i].ptd = NULL;
     67            }
    7268
    73         delete[] m_paFormatEtc;
     69        RTMemFree(m_paFormatEtc);
    7470        m_paFormatEtc = NULL;
    7571    }
     
    149145STDMETHODIMP VBoxDnDEnumFormatEtc::Clone(IEnumFORMATETC **ppEnumFormatEtc)
    150146{
    151     HRESULT hResult =
    152         CreateEnumFormatEtc(m_cFormats, m_paFormatEtc, ppEnumFormatEtc);
     147    HRESULT hrc = CreateEnumFormatEtc(m_cFormats, m_paFormatEtc, ppEnumFormatEtc);
    153148
    154     if (hResult == S_OK)
     149    if (hrc == S_OK)
    155150        ((VBoxDnDEnumFormatEtc *) *ppEnumFormatEtc)->m_uIdxCur = m_uIdxCur;
    156151
    157     return hResult;
     152    return hrc;
    158153}
    159154
     
    180175    AssertPtrReturn(ppEnumFormatEtc, E_INVALIDARG);
    181176
    182     HRESULT hr;
    183     try
     177#ifdef RT_EXCEPTIONS_ENABLED
     178    try { *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, nNumFormats); }
     179    catch (std::bad_alloc &)
     180#else
     181    *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, nNumFormats);
     182    if (!*ppEnumFormatEtc)
     183#endif
    184184    {
    185         *ppEnumFormatEtc = new VBoxDnDEnumFormatEtc(pFormatEtc, nNumFormats);
    186         hr = S_OK;
    187     }
    188     catch(std::bad_alloc &)
    189     {
    190         hr = E_OUTOFMEMORY;
     185        return E_OUTOFMEMORY;
    191186    }
    192187
    193     return hr;
     188    return S_OK;
    194189}
    195190
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette