Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ IMAPITable::GetContentsTable+;GetRowCount检索不一致的结果_C++_Email_Outlook_Mapi - Fatal编程技术网

C++ IMAPITable::GetContentsTable+;GetRowCount检索不一致的结果

C++ IMAPITable::GetContentsTable+;GetRowCount检索不一致的结果,c++,email,outlook,mapi,C++,Email,Outlook,Mapi,我面临着一个尴尬的场景,下面的API调用返回不一致的结果,或者更准确地说,在GetRowCount产生任何重要结果之前,我必须.Release()目录几次 if(FAILED(hr = spFolder->CreateFolder(FOLDER_SEARCH, &strOutLookSearchFolder[0], nullptr, nullptr, MAPI_UNICODE | OPEN_IF_EXISTS, &spSearchFolder)))

我面临着一个尴尬的场景,下面的API调用返回不一致的结果,或者更准确地说,在
GetRowCount
产生任何重要结果之前,我必须
.Release()
目录几次

    if(FAILED(hr = spFolder->CreateFolder(FOLDER_SEARCH, &strOutLookSearchFolder[0],
        nullptr, nullptr, MAPI_UNICODE | OPEN_IF_EXISTS, &spSearchFolder)))
    {
        throw Exception("Failed creating search folder", hr);
    }

    if(FAILED(hr = spSearchFolder->SetSearchCriteria(spSRestriction_.get(),
        spEntryList.get(), RESTART_SEARCH | RECURSIVE_SEARCH | FOREGROUND_SEARCH)))
    {
        throw Exception("Failed setting search criteria", hr);
    }

ATL::CComPtr<IMAPITable> spContentsTable;
    if(FAILED(hr = spSearchFolder->GetContentsTable(0, &spContentsTable)))
    {
        LOG(ERR) << "Failed getting contents table";
        return;
    }

    ULONG ulMailCount = 0;
    if(SUCCEEDED(spContentsTable->GetRowCount(0, &ulMailCount)))
        spDataModelSubFolder->AddMessagesCount(ulMailCount);
if(失败)(hr=spFolder->CreateFolder(文件夹搜索,&strOutLookSearchFolder[0]),
nullptr、nullptr、MAPI_UNICODE |如果存在则打开,&spSearchFolder)))
{
抛出异常(“创建搜索文件夹失败”,hr);
}
如果(失败)(hr=spSearchFolder->SetSearchCriteria(spSRestriction.get()),
spEntryList.get(),重新启动搜索(递归搜索(前台搜索)))
{
抛出异常(“设置搜索条件失败”,hr);
}
ATL::CComPtr spContentsTable;
if(失败(hr=spSearchFolder->GetContentsTable(0,&spContentsTable)))
{
日志(错误)GetRowCount(0,&ulMailCount)))
spDataModelSubFolder->addmessagescont(ulMailCount);
编辑:

以上代码崩溃(DispatchMessage)天气与否我输入SetSearchCriteria

ATL::CComPtr<IMAPISession> spSession;
        if(FAILED(hr = pfnMAPILogonEx_(0, &profile.GetProfileName()[0], NULL,
                                MAPI_NEW_SESSION | MAPI_EXTENDED | /*MAPI_NO_MAIL |*/ MAPI_UNICODE, &spSession)))
                            {
                                continue;
                            }

                ....
                ....
                ....

               auto pfnHrAllocAdviseSink = (decltype(&::HrAllocAdviseSink))GetProcAddress(
                        (HMODULE)spMapiModule_.get(), "HrAllocAdviseSink@12"); 

                    ATL::CComPtr<IMAPIAdviseSink>   spAdviseSink;
                    bool                            bSearchCompleted =  false;
                    if(FAILED(hr = pfnHrAllocAdviseSink(SearchCompleteCallBack, 
                        &bSearchCompleted, &spAdviseSink)))
                    {
                        throw OutlookException("Failed allocating advise sink");
                    }

                    ULONG ulConnection = 0;
                    if(FAILED(hr = spMsgStore->Advise(
                        spPropSearchFolderEntryID->Value.bin.cb,
                        (LPENTRYID)spPropSearchFolderEntryID->Value.bin.lpb,
                        fnevSearchComplete,
                        spAdviseSink,
                        &ulConnection)))
                    {
                        throw OutlookException("Failed creating event sink");
                    }   

                    if(FAILED(hr = spSearchFolder->SetSearchCriteria(spSRestriction_.get(),
                        spEntryList.get(), RESTART_SEARCH | RECURSIVE_SEARCH)))
                    {
                        throw OutlookException("Failed setting search criteria", hr);
                    }

                    MSG msg = { 0 };
                    while (GetMessage(&msg, NULL, 0 ,0))
                    {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                        if (bSearchCompleted)
                            break;              
                    }   

    ....
    ....
    ....

    LONG STDAPICALLTYPE SearchCompleteCallBack(
        LPVOID          lpvContext,
        ULONG           cNotif,
        LPNOTIFICATION  lpNotif)
    {
        bool* pbSearchCompleted = (bool*)lpvContext;
        *pbSearchCompleted = true;
        return SUCCESS_SUCCESS;
    }
ATL::CComPtr spSession;
如果(失败)(hr=pfnMAPILogonEx_0,&profile.GetProfileName()[0],则为NULL,
MAPI|U NEW|U SESSION | MAPI|U EXTENDED |/*MAPI|U NO|U MAIL |*/MAPIUUnicode,&SPSSESSION)))
{
继续;
}
....
....
....
自动PFNHRALLOCADVISENK=(decltype(&::hrAllocadvisink))GetProcAddress(
(HMODULE)spMapiModule_u2;.get()HrAllocAdviseSink@12"); 
ATL::CComPtr接收器;
boolbsearchcompleted=false;
如果(失败)(hr=pfnHrAllocAdviseSink(SearchCompleteCallBack,
&b搜索已完成,&b)
{
抛出OutlookException(“分配通知接收器失败”);
}
ULONG-ulConnection=0;
如果(失败)(hr=spMsgStore->advice(
spPropSearchFolderEntryID->Value.bin.cb,
(LPENTRYID)spPropSearchFolderEntryID->Value.bin.lpb,
fnevSearchComplete,
铁锹水槽,
&(连接)
{
抛出OutlookException(“创建事件接收器失败”);
}   
如果(失败)(hr=spSearchFolder->SetSearchCriteria(spSRestriction.get()),
spEntryList.get(),重新启动搜索(递归搜索)))
{
抛出OutlookException(“设置搜索条件失败”,hr);
}
MSG={0};
while(GetMessage(&msg,NULL,0,0))
{
翻译信息(&msg);
发送消息(&msg);
如果(b搜索已完成)
打破
}   
....
....
....
长STDAPICALLTYPE SearchCompleteCallBack(
LPVOID lpvContext,
乌龙cNotif,
lpNotif通知(lpNotif)
{
bool*pbSearchCompleted=(bool*)lpvContext;
*pbSearchCompleted=true;
回报成功;
}

指向同一文件夹目录的两个不同指针?看起来这是一个错误,因为持续的调试尝试没有很好地结束,我刚刚意识到我需要使用AdviseSink并等待SetSearchCriteria完成Mitry Streblechenko:是否可以在不执行HrAllocAdviseSink的情况下创建IMAPIAdviseSink?I我使用olmapi32.dll,不能依赖mapi32.dllYou应该加载olmapi32.dlll-加载msmapi32.dll。它实现HrAllocAdviseSink以及所有其他MAPI函数。是的,您不必使用HrAllocAdviseSink-我从不使用该函数,而是创建自己的COM对象来实现IMAPIAdviseSink接口。最后一个事情是这样的,我的DispatchMessage崩溃了,不管我在做什么,等待还是不等待,或者SetSearchCriteria