1

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

无论如何,如果我有 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;
}
4

1 回答 1

0

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

"\\Mailbox - <user_name>\\Calendar"
于 2012-05-31T18:52:48.097 回答