Share via


Check the Version of Outlook

Check the Version of Outlook

This topic shows a code sample that checks the version of Outlook that is running.

Some of the APIs in the Outlook 2007 Auxiliary Reference apply only to Microsoft Office Outlook 2003 Service Pack 1 and Outlook 2007. To downgrade or fail gracefully, an add-in or mail provider that uses these APIs must determine the version of Outlook that is being used.

The following code sample obtains the full version string by using MsiProvideQualifiedComponent and MsiGetFileVersion, as declared in msi.h in the Microsoft® Windows® Software Development Kit (SDK). To ensure that the integration API will work for Outlook 2003 SP1, verify that the major build number in the version string is equal to 11 and the build number (which is the third number in the version string) is greater than or equal to 6359.

  HRESULT GetOutlookVersionString(LPTSTR* ppszVer)
{
    HRESULT hr = E_FAIL;
    LPTSTR pszTempPath = NULL;
    LPTSTR pszTempVer = NULL;
    TCHAR pszaOutlookQualifiedComponents[][MAX_PATH] = {
        TEXT("{BC174BAD-2F53-4855-A1D5-0D575C19B1EA}"),
        TEXT("{BC174BAD-2F53-4855-A1D5-1D575C19B1EA}") };
    int  nOutlookQualifiedComponents = 2;
    int i = 0;
    DWORD dwValueBuf = 0;
    UINT ret = 0;
assert(ppszVer);

for (i = 0; i < nOutlookQualifiedComponents; i++)
{
    ret = MsiProvideQualifiedComponent(
        pszaOutlookQualifiedComponents[i],
        TEXT("outlook.exe"),
        INSTALLMODE_DEFAULT,
        NULL,
        &dwValueBuf);

    if (ret == ERROR_SUCCESS)
    {
        break;
    }
}

if (ret == ERROR_SUCCESS)
{
    dwValueBuf += 1;
    pszTempPath = (LPTSTR) malloc(dwValueBuf * sizeof(TCHAR));
	
    if (pszTempPath != NULL)
    {
        if ((ret = MsiProvideQualifiedComponent( pszaOutlookQualifiedComponents[i],
            TEXT("outlook.exe"),
            INSTALLMODE_EXISTING,
            pszTempPath,
            &dwValueBuf)) !=ERROR_SUCCESS)
        {
            goto Error;
        }

        pszTempVer = (LPTSTR) malloc(MAX_PATH * sizeof(TCHAR));
            dwValueBuf = MAX_PATH;
        if ((ret =  MsiGetFileVersion(pszTempPath,
            pszTempVer,
            &dwValueBuf,
            NULL,
            NULL))!= ERROR_SUCCESS)
        {
            goto Error;	
        }
        *ppszVer = pszTempVer;
        pszTempVer = NULL;
        hr = S_OK;
    }
}

Error: free(pszTempVer); free(pszTempPath); return hr; }

See Also

Outlook 2007 Auxiliary Reference: Overview