“OpenProperty期间没有支持此类接口(0x80004002)”错误

时间:2015-02-20 03:31:51

标签: mapi

我使用以下代码获取IPM_SUBTREE下的所有文件夹。同样在所有计算机上工作正常。

但是,在其中一台客户机器中,这不起作用。在分析日志时,我们发现OpenProperty返回0x80004002

const GUID local_IID_IMAPITable = {0x00020301,0,0, {0xC0,0,0,0,0,0,0,0x46}}; 
hr = lpRootFolder->OpenProperty(    PR_CONTAINER_HIERARCHY, 
                            &local_IID_IMAPITable, 
                            0, 
                            0, 
                            (IUnknown**)&lpHierarchyTable); 

以下是完整的代码

BOOL CMapiSession::DisplayIPMSubTree() 
{ 
    BOOL        bReturn = FALSE; 

    HRESULT     hr = S_OK; 

    LPSPropValue    lpProp = NULL; 

    LPMAPIFOLDER    lpRootFolder = NULL; 

    LPMAPITABLE lpHierarchyTable = NULL; 

    LPSRowSet   sRows = NULL;   

    LPMAPIFOLDER    lpContactsFolder = NULL; 

    do 
    { 
        //Before the function make sure that OpenMsgStore() is done 

        if (NULL == m_lpMsgStore) 
        { 
            PAS_ERROR(("%s: lpMsgStore can not be empty", __FUNCTION__)); 

            break; 
        } 

        hr = HrGetOneProp(m_lpMsgStore, PR_IPM_SUBTREE_ENTRYID, &lpProp); 

        if (FAILED(hr)) 
        { 
            PAS_ERROR(("%s: Failed in HrGetOneProp . HRESULT=[0x%x]", __FUNCTION__, hr)); 

            LogMapiError(hr); 

            break; 
        } 

        if (NULL == lpProp) 
        { 
            PAS_ERROR(("%s: PR_IPM_SUBTREE_ENTRYID is NULL.", __FUNCTION__)); 

            break; 
        } 

/*      if (lpProp->ulPropTag != PR_ENTRYID) 
        { 
            PAS_ERROR(("%s: Returned value is not PR_ENTRYID.", __FUNCTION__)); 

            break; 
        } 
*/ 

        ULONG ipmroottype; 
        hr = m_lpMsgStore->OpenEntry(lpProp->Value.bin.cb, 
                                     (LPENTRYID)lpProp->Value.bin.lpb, 
                                     NULL, 
                                     0, 
                                     &ipmroottype, 
                                     (IUnknown**)&lpRootFolder); 

        if (FAILED(hr)) 
        { 
            PAS_ERROR(("%s: Failed in OpenEntry . HRESULT=[0x%x]", __FUNCTION__, hr)); 

            LogMapiError(hr); 

            break; 
        } 

        if (NULL == lpRootFolder) 
        { 
            PAS_ERROR(("%s: Root is NULL", __FUNCTION__)); 

            break; 
        } 

        if (ipmroottype!=MAPI_FOLDER) 
        { 
            PAS_ERROR(("%s: Root is not a folder", __FUNCTION__)); 

            break; 
        } 


        const GUID local_IID_IMAPITable = {0x00020301,0,0, {0xC0,0,0,0,0,0,0,0x46}}; 
        hr = lpRootFolder->OpenProperty(    PR_CONTAINER_HIERARCHY, 
                                    &local_IID_IMAPITable, 
                                    0, 
                                    0, 
                                    (IUnknown**)&lpHierarchyTable); 

        if (FAILED(hr)) 
        { 
            PAS_ERROR(("%s: Failed in OpenProperty . HRESULT=[0x%x]", __FUNCTION__, hr)); 

            LogMapiError(hr); 

            break; 
        } 

        if (lpHierarchyTable == NULL) 
        { 
            PAS_ERROR(("%s: lpHierarchyTable is NULL ", __FUNCTION__)); 

            break; 
        } 

        SizedSPropTagArray(3, cols) = {3, {PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS} }; 

        hr = HrQueryAllRows(    lpHierarchyTable, 
                                        (SPropTagArray*)&cols, 
                                        NULL, 
                                        NULL, 
                                        0, 
                                        &sRows); 

        if (FAILED(hr)) 
        { 
            PAS_ERROR(("%s: Failed in HrQueryAllRows . HRESULT=[0x%x]", __FUNCTION__, hr)); 

            LogMapiError(hr); 

            break; 
        } 

        if (sRows == NULL) 
        { 
            PAS_ERROR(("%s: sRows is NULL ", __FUNCTION__)); 

            break; 
        } 

        for (unsigned int i=0; i<sRows->cRows; i++) 
        { 
            std::wstring csFolderName = sRows->aRow[i].lpProps[1].Value.lpszW; 

            std::wstring csContainerClass; 

            if(PROP_TYPE(sRows->aRow[i].lpProps[2].ulPropTag) != PT_NULL) 
            { 
                if(PROP_TYPE(sRows->aRow[i].lpProps[2].ulPropTag) != PT_ERROR) 
                { 
                    if (sRows->aRow[i].lpProps[2].Value.err != MAPI_E_NOT_FOUND) 
                    { 
                        csContainerClass = sRows->aRow[i].lpProps[2].Value.lpszW; 
                    } 
                } 
            } 

            PAS_TRACE(("%s: Folder=[%s], ContainerClass=[%s] ", __FUNCTION__, csFolderName.c_str(), csContainerClass.c_str())); 
        } 

        bReturn = TRUE; 
    } 
    while(FALSE); 

    if (lpContactsFolder) 
    { 
        PAS_TRACE(("%s: Freeing the lpContactsFolder-2", __FUNCTION__)); 

        lpContactsFolder->Release(); 

        lpContactsFolder = NULL; 
    } 

    if (sRows) 
    { 
        PAS_TRACE(("%s: Freeing the sRows", __FUNCTION__)); 

        FreeProws(sRows); 

        sRows = NULL; 
    } 

    if (lpHierarchyTable) 
    { 
        PAS_TRACE(("%s: Freeing the lpHierarchyTable", __FUNCTION__)); 

        lpHierarchyTable->Release(); 

        lpHierarchyTable = NULL; 
    } 

    if (lpRootFolder) 
    { 
        PAS_TRACE(("%s: Freeing the lpRootFolder", __FUNCTION__)); 

        lpRootFolder->Release(); 

        lpRootFolder = NULL; 
    } 

    if (lpProp) 
    { 
        PAS_TRACE(("%s: Freeing the lpProp", __FUNCTION__)); 

        MAPIFreeBuffer(lpProp); 

        lpProp = NULL; 
    } 

    return bReturn; 
} 

如果您需要更多详细信息,请与我们联系。任何帮助表示赞赏。

此致 罗汉

1 个答案:

答案 0 :(得分:0)

请改用lpRootFolder-&gt; OpenHieirarchyTable()。