Exemplo n.º 1
0
HRESULT STDMETHODCALLTYPE CSHEnumClassesOfCategories::Skip(ULONG nbElts)
{
    if (fCursor + nbElts >= (ULONG)DSA_GetItemCount(fDsa))
        return E_INVALIDARG;
    fCursor += nbElts;
    return S_OK;
}
Exemplo n.º 2
0
HRESULT CComCatCachedCategory::WriteCacheToDSA(HDSA pDest)
{
    INT i;
    for(i = 0; i < DSA_GetItemCount(fLocalDsa); i++)
    {
        if (DSA_InsertItem(pDest, DSA_APPEND, DSA_GetItemPtr(fLocalDsa, i)) == DSA_ERR)
            return E_OUTOFMEMORY;
    }
    return S_OK;
}
Exemplo n.º 3
0
HRESULT CComCatCachedCategory::CacheDSA()
{
    WCHAR                               bufKey[MAX_PATH];
    WCHAR                               guidStr[MAX_PATH];
    UINT                                elemCount;
    UINT                                i;
    UINT                                bufferSize;
    CComHeapPtr<CATCACHEHDR>            buffer;
    GUID                                *guidArray;
    GUID                                *tmp;

    elemCount = DSA_GetItemCount(fLocalDsa);
    bufferSize = sizeof(CATCACHEHDR) + elemCount * sizeof(GUID);
    if (!StringFromGUID2(fCategory, guidStr, MAX_PATH))
        return E_FAIL;

    buffer.Attach((PCATCACHEHDR)CoTaskMemAlloc(bufferSize));
    if (!buffer)
        return E_OUTOFMEMORY;

    // Correctly fill cache header
    buffer->dwSize = sizeof(CATCACHEHDR);
    buffer->version = 1;
    GetSystemTime(&buffer->writeTime);
    buffer->classCount = (DWORD)elemCount;

    guidArray = (GUID*)(buffer + 1);
    wsprintf(bufKey, L"%s\\%s\\%s", REGPATH , guidStr, L"Enum");

    // Write DSA contents inside the memory buffer allocated
    for(i = 0; i < elemCount; i++)
    {
        tmp = (GUID*)DSA_GetItemPtr(fLocalDsa, i);
        if (tmp)
        {
            guidArray[i] = *tmp;
        }
    }

    // Save items to registry
    SHSetValue(HKEY_CURRENT_USER, bufKey, IMPLEMENTING, REG_BINARY, buffer, bufferSize);

    guidArray = NULL;
    return S_OK;
}
Exemplo n.º 4
0
HRESULT _FindRegisteredClass(const CLSID *pclsid, IClassFactory **ppCF)
{
    INT i;

    *ppCF = NULL;

    if (!hdsaRegClasses)
        return REGDB_E_CLASSNOTREG;     // A nice sounding error code...

    for (i = DSA_GetItemCount(hdsaRegClasses) - 1; i >= 0; i--)
    {
        SHREGCLASS *lpsrc;
        lpsrc = DSA_GetItemPtr(hdsaRegClasses, i);
        if (lpsrc != NULL && lpsrc->pUnk != NULL)
        {
            if (IsEqualIID(pclsid, &lpsrc->clsid))
                return lpsrc->pUnk->lpVtbl->QueryInterface(lpsrc->pUnk, &IID_IClassFactory, ppCF);
        }
    }
    return REGDB_E_CLASSNOTREG;     // A nice sounding error code...
}
Exemplo n.º 5
0
HRESULT STDMETHODCALLTYPE CSHEnumClassesOfCategories::Next(ULONG cElt, CLSID *pElts, ULONG *pFetched)
{
    ULONG i;
    ULONG read;
    GUID *tmp;

    if (!pElts)
        return E_INVALIDARG;
    read = 0;
    for (i = 0; i < cElt && (fCursor < (ULONG)DSA_GetItemCount(fDsa)); i++)
    {
        tmp = (GUID*)DSA_GetItemPtr(fDsa, fCursor + i);
        if (!tmp)
            break;
        pElts[i] = *tmp;
        read++;
    }
    fCursor += read;
    if (pFetched)
        *pFetched = read;
    return S_OK;
}
Exemplo n.º 6
0
static HRESULT PopulateNetworkList(PWLAN_INFO psInfo)
{
    HRESULT hr = S_OK;
    LPCTSTR pszConnected, pszConnecting, pszAvailable, pszUnavailable;
    LV_ITEM lv = { 0 };
    UINT    i, cConfigs;
    BOOL    fNetAvailable = FALSE;

    CBREx(psInfo, E_INVALIDARG);

    // Load strings
    pszConnected = (LPCTSTR)LoadString(HINST_RESDLL, IDS_WZC_ACTIVE, NULL, 0);
    CBRA(NULL != pszConnected);

    pszConnecting = (LPCTSTR)LoadString(HINST_RESDLL, IDS_WZC_CONNECTING, NULL, 0);
    CBRA(NULL != pszConnecting);

    pszAvailable = (LPCTSTR)LoadString(HINST_RESDLL, IDS_WZC_AIRING, NULL, 0); 
    CBRA(NULL != pszAvailable);

    pszUnavailable = (LPCTSTR)LoadString(HINST_RESDLL, IDS_WZC_SILENT, NULL, 0); 
    CBRA(NULL != pszUnavailable);

    // Add the first setting item
    hr = InsertFirstSettingsItem(psInfo);
    CHR(hr);

    // Get the network list
    hr = SHWZCGetAllNetworks(psInfo->hshwzc, &psInfo->hdsaNetworks);
    CHR(hr);

    // Are there any items?
    cConfigs = DSA_GetItemCount(psInfo->hdsaNetworks);
    CBREx(0 != cConfigs, S_FALSE);
    ListView_SetItemCount(psInfo->hwndNetList, cConfigs + 1);

    // Add the networks to the list
    for (i = 0; i != cConfigs; ++i)
    {
        PCSHWZCNET pwzcnet = (PSHWZCNET)DSA_GetItemPtr(psInfo->hdsaNetworks, i);
        BOOL       fAdhoc = (SHWZCF_NET_ADHOC & pwzcnet->dwFlags);
        BOOL       fSecure;
        LPCTSTR    pszDesc;
        int        nIndex;
        BOOL       fUseSignalStrength = FALSE;

        // If this network is AP, mark it
        if (FALSE == fAdhoc)
        {
            psInfo->fAPAir = TRUE;
            fUseSignalStrength = TRUE;
        }

        // network is considered secure if it's 802.1x, or not OPEN and without
        // encryption enabled
        fSecure = BOOLIFY(pwzcnet->dwFlags & SHWZCF_NET_8021X) ||
            !( ( (Ndis802_11Encryption1Enabled != pwzcnet->dwEncryptionType) &&
            (Ndis802_11Encryption2Enabled != pwzcnet->dwEncryptionType) &&
            (Ndis802_11Encryption3Enabled != pwzcnet->dwEncryptionType) ) &&
            (Ndis802_11AuthModeOpen == pwzcnet->dwAuthentication) );

        // Get the icon and the description for the network
        if (SHWZCF_NET_CONNECTED & pwzcnet->dwFlags)
        {
            lv.iImage = fAdhoc ? WZCIMG_ADHOC_ACTIVE : 0;
            pszDesc = pszConnected;
        }
        else if (SHWZCF_NET_CONNECTING & pwzcnet->dwFlags)
        {
            lv.iImage = fAdhoc ? WZCIMG_ADHOC_AIRING : 0;
            pszDesc = pszConnecting;
        }
        else if (SHWZCF_NET_BROADCAST & pwzcnet->dwFlags)
        {
            lv.iImage = fAdhoc ? WZCIMG_ADHOC_AIRING : 0;
            pszDesc = pszAvailable;
        }
        else
        {
            ASSERT(SHWZCF_NET_PREFERRED & pwzcnet->dwFlags);
            lv.iImage = fAdhoc ? WZCIMG_ADHOC_SILENT : WZCIMG_INFRA_SILENT;

            pszDesc = pszUnavailable;
            // no need to get signal strength
            fUseSignalStrength = FALSE;
        }

        if (SHWZCF_NET_BROADCAST & pwzcnet->dwFlags)
        {
            fNetAvailable = TRUE;
        }

        // Update the icon to have signal strength if we're in Infrastructure mode
        if (fUseSignalStrength)
        {
            UINT uiStrength = pwzcnet->nRssi;

            if (uiStrength)
            {
                lv.iImage = WZCIMG_SIGNAL_1 + uiStrength - 1;
                if (fSecure)
                {
                    lv.iImage += WZCIMG_SIGNAL_SECURE_1 - WZCIMG_SIGNAL_1;
                }
            }
            else
            {
                lv.iImage = WZCIMG_INFRA_SILENT;
            }
        }

        ASSERT(lv.iImage);

        // Insert the item into the listview
        lv.mask     = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
        lv.iItem    = i;
        lv.iSubItem = 0;
        lv.pszText  = (LPTSTR)pwzcnet->szName;
        lv.lParam   = (LPARAM)pwzcnet;

        nIndex = ListView_InsertItem(psInfo->hwndNetList, &lv);
        CBR(0 <= nIndex);

        // Set the state text
        lv.mask     = LVIF_TEXT;
        lv.iItem    = nIndex;
        lv.iSubItem = 1;
        lv.pszText  = (LPTSTR)pszDesc;

        CBR(ListView_SetItem(psInfo->hwndNetList, &lv));
    }

    // Sort the networks
    CBREx(ListView_SortItems(psInfo->hwndNetList, CompareNetworks, NULL), E_OUTOFMEMORY);

Error:

    if(psInfo)
    {
        SetCursor(psInfo->hOldCursor);
        psInfo->hOldCursor = NULL;

        // We just turned power on, but didn't find any broadcasting networks
        if((psInfo->bUserInitiatedSearch) && (!fNetAvailable) && (psInfo->dwHWFlags & SHWZCF_HW_ON))
        {
            psInfo->bUserInitiatedSearch = FALSE;
            SH_BOXEX sbex = {0};
            sbex.cbSize = sizeof(sbex);
            sbex.dwStyle = SHBEXF_CLOSE_ON_ACTIVATION_LOSS|SHBEXF_SUPRESS_DEFAULT_SOUND;
            sbex.nTimeOut = 0;
            sbex.hwndOwner = psInfo->hDlg;
            sbex.sbextype = sbextTextBox;
            sbex.info.ti.pszText = LoadStringEtc(HINST_RESDLL, IDS_WZC_WIFI_SEARCH_ERROR, NULL);
            sbex.info.ti.bi.cButtons = 1;
            
            SHBoxEx(&sbex);
        }

        psInfo->bUserInitiatedSearch = FALSE;
    }
    
    return hr;
}
Exemplo n.º 7
0
BOOL PASCAL TV_SortCB(PTREE pTree, TV_SORTCB FAR *pSortCB, BOOL bRecurse,
        PFNDPACOMPARE lpfnDPACompare)
{
        HDPA dpaSort;
        HDSA dsaCmp;
        HTREEITEM hItem, hNext, hFirstMoved;
        LPTVCOMPARE psCompare, FAR *ppsCompare;
        int i, cKids;
        HTREEITEM hParent = pSortCB->hParent;

#ifdef DEBUG
        DWORD dwTime = GetTickCount();
        nCompares = 0;
#endif

        if (!hParent || hParent == TVI_ROOT)
            hParent = pTree->hRoot;

        // Code below assumes at least one kid
        cKids = TV_CountKids(hParent);
        if (!cKids)
            return FALSE;

        // Create a DSA for all the extra info we'll need
        dsaCmp = DSA_Create(sizeof(TVCOMPARE), cKids);
        if (!dsaCmp)
            goto Error1;

        // Create a DPA containing all the tree items
        dpaSort = DPA_Create(cKids);
        if (!dpaSort)
            goto Error2;

        for (hItem = hParent->hKids; hItem; hItem = hItem->hNext)
        {
                TVCOMPARE sCompare;
                int nItem;

                // If I can't sort all of them, I don't want to sort any of them

                // We want to cache the text callback for default processing
                if (!lpfnDPACompare && hItem->lpstr==LPSTR_TEXTCALLBACK)
                {
                        TV_ITEM sItem;
                        TCHAR szTemp[MAX_PATH];

                        sItem.pszText = szTemp;
                        sItem.cchTextMax  = ARRAYSIZE(szTemp);
                        TV_GetItem(pTree, hItem, TVIF_TEXT, &sItem);

                        sCompare.lpstr = NULL;
                        sCompare.bCallBack = TRUE;
                        Str_Set(&sCompare.lpstr, sItem.pszText);
                        if (!sCompare.lpstr)
                        {
                                goto Error3;
                        }
                }
                else
                {
                        sCompare.lpstr = hItem->lpstr;
                        sCompare.bCallBack = FALSE;
                }

                // Create the pointer for this guy and add it to the DPA list
                sCompare.hItem = hItem;
                nItem = DSA_InsertItem(dsaCmp, 0x7fff, &sCompare);
                if (nItem < 0)
                {
                        if (sCompare.bCallBack)
                        {
                                Str_Set(&sCompare.lpstr, NULL);
                        }
                        goto Error3;
                }

                if (DPA_InsertPtr(dpaSort, 0x7fff, DSA_GetItemPtr(dsaCmp, nItem)) < 0)
                {
                        goto Error3;
                }
        }

        // Sort the DPA, then stick them back under the parent in the new order
        DPA_Sort(dpaSort, lpfnDPACompare ? (PFNDPACOMPARE)lpfnDPACompare :
                 (PFNDPACOMPARE) TV_DefCompare, (LPARAM)pSortCB);


        // Look for the first moved item, so we can invalidate a smaller area
        ppsCompare = (LPTVCOMPARE FAR *)DPA_GetPtrPtr(dpaSort);
        if (hParent->hKids != (*ppsCompare)->hItem)
        {
                hParent->hKids = (*ppsCompare)->hItem;
                hFirstMoved = hParent->hKids;
        }
        else
        {
                hFirstMoved = NULL;
        }

        // We do n-1 iterations here
        for (i = DPA_GetPtrCount(dpaSort) - 1; i > 0; --i, ++ppsCompare)
        {
                hNext = (*(ppsCompare+1))->hItem;
                if ((*ppsCompare)->hItem->hNext != hNext && !hFirstMoved)
                {
                        hFirstMoved = hNext;
                }
                (*ppsCompare)->hItem->hNext = hNext;
        }
        (*ppsCompare)->hItem->hNext = NULL;

        TV_UpdateShownIndexes(pTree, hParent);
        if ((pSortCB->hParent == TVI_ROOT) || !hParent) {
            if (pTree->cShowing < pTree->cFullVisible) {
                pTree->hTop = pTree->hRoot->hKids;
            }
        }

        if (hFirstMoved && (hParent->state & TVIS_EXPANDED))
        {
                RECT rcUpdate;

                TV_GetItemRect(pTree, hFirstMoved, &rcUpdate, FALSE);
                if (hParent->hNext)
                {
                        RECT rcTemp;

                        TV_GetItemRect(pTree, hParent->hNext, &rcTemp, FALSE);
                        rcUpdate.bottom = rcTemp.bottom;
                }
                else
                {
                        RECT rcClient;
                        GetClientRect(pTree->ci.hwnd, &rcClient);
                        // Set to maximal positive number, so the whole rest of
                        // the treeview gets invalidated
                        rcUpdate.bottom = rcClient.bottom;
                }
                if (pTree->fRedraw)
                    InvalidateRect(pTree->ci.hwnd, &rcUpdate, TRUE);
        }

Error3:
        DPA_Destroy(dpaSort);
Error2:
        for (i = DSA_GetItemCount(dsaCmp) - 1; i >= 0; --i)
        {
                psCompare = DSA_GetItemPtr(dsaCmp, i);
                if (psCompare->bCallBack)
                {
                        Str_Set(&(psCompare->lpstr), NULL);
                }
        }
        DSA_Destroy(dsaCmp);
Error1:

#ifdef DEBUG
        DebugMsg(DM_TRACE, TEXT("tv.sort: %ld ms; %d cmps"), GetTickCount()-dwTime, nCompares);
#endif

    {
        int wNewPos;
        // restore the scroll position
        if (GetWindowStyle(pTree->ci.hwnd) & WS_VSCROLL) {
            SCROLLINFO si;

            si.cbSize = sizeof(SCROLLINFO);
            si.fMask = SIF_POS;
            wNewPos = 0;
            if (GetScrollInfo(pTree->ci.hwnd, SB_VERT, &si)) {
                wNewPos = si.nPos;
            }

        } else {
            wNewPos = 0;
        }

        if (TV_SetTopItem(pTree, wNewPos))
            UpdateWindow(pTree->ci.hwnd);
    }

    // if the caret is the child of the thing that was sorted, make sure it's
    // visible (but if we're sorting something completely unrelated, don't bother
    if (pTree->hCaret) {
        hItem = pTree->hCaret;
        do {
            // do this first.  if hParent is hCaret, we don't want to ensure visible...
            // only if it's an eventual child
            hItem = hItem->hParent;
            if (hParent == hItem) {
                TV_EnsureVisible(pTree, pTree->hCaret);
            }
        } while(hItem && hItem != pTree->hRoot);
    }

    return TRUE;
}