IsSearchSynchronous在Outlook中失败

时间:2012-05-22 20:10:46

标签: outlook office-automation

我正在使用Outlook自动化在日历中查找项目。为此,我使用IsSearchSynchronous()方法来查看是否必须等待AdvancedSearchComplete事件。 BTW,它是否曾经同步???

无论如何,如果我运行Outlook,我对此调用没有任何问题。但如果它没有运行 - 调用失败并带有

HRESULT: 0x80020009 Exception occurred

EXCEPINFO包含:

Source: "Microsoft Outlook"
Description: "The operation failed."
scode: 0x80004005

有什么建议吗? 这是我的测试用例:

#include <atlstr.h>

int _tmain()
{
    IDispatch*  pApp;
    HRESULT     hr;
    CoInitialize(NULL);
    CLSID clsid;
    hr = CLSIDFromProgID(L"Outlook.Application", &clsid);
    if(SUCCEEDED(hr))
    {
        hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&pApp);
        if(SUCCEEDED(hr))
        {
            // Get DISPID for "IsSearchSynchronous"
            OLECHAR Name[] = {L"IsSearchSynchronous"};
            LPOLESTR lp = Name;
            DISPID dispID;
            hr = pApp->GetIDsOfNames(IID_NULL, &lp, 1, LOCALE_USER_DEFAULT, &dispID);
            if(SUCCEEDED(hr))
            {
                // The path name of the folders that the search will search through.
                VARIANT path;
                path.vt = VT_BSTR;
                path.bstrVal = SysAllocString(L"'Calendar'");

                // Build DISPPARAMS
                DISPPARAMS dp = { NULL, NULL, 0, 0 };
                dp.cArgs = 1;
                dp.rgvarg = &path;

                // get IsSearchSynchronous
                VARIANT result;
                VariantInit(&result);
                EXCEPINFO ei = {0};
                hr = pApp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dp, &result, &ei, NULL);
                VARIANT_BOOL vbIsSearchSynchronous = result.boolVal;
            }
        }
    }
    CoUninitialize();
    return 0;
}

1 个答案:

答案 0 :(得分:0)

如果有其他人感兴趣,可以在Microsoft的帮助下解决此问题。 IsSearchSynchronous()调用的“scope”参数应该是日历文件夹的完整路径,如:

"\\Mailbox - <user_name>\\Calendar"