IsSearchSynchronous fails in Outlook

0

I am using Outlook automation to find items in the Calendar. For that I use IsSearchSynchronous() method to see if I have to wait for the AdvancedSearchComplete event. BTW, is it ever synchronous???

Anyway, if I have Outlook running, I have no problems with this call. But if it doesn't run - the call fails with

HRESULT: 0x80020009 Exception occurred

The EXCEPINFO contains:

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

Any suggestions? Here is my test case:

#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;
}
outlook
office-automation
asked on Stack Overflow May 22, 2012 by Vlad Feinstein

1 Answer

0

In case anybody else is interested, this is resolved with a help from Microsoft. The “scope” parameter to a IsSearchSynchronous() call should be a complete path to the calendar folder, like:

"\\Mailbox - <user_name>\\Calendar"
answered on Stack Overflow May 31, 2012 by Vlad Feinstein

User contributions licensed under CC BY-SA 3.0