Click here to Skip to main content
15,884,629 members
Articles / Desktop Programming / Win32

Outlook add-in integrating Skype

Rate me:
Please Sign up or sign in to vote.
4.93/5 (32 votes)
28 May 2015CPOL20 min read 68.7K   2.4K   54  
Outlook add-in integration for Skype IM: Skype events, Outlook Skype ribbon, and more.
#include "Sdk.h"
#include "ShUtils.h"
#include "ComUtils.h"
#include "StringMgr.h"

BOOL
ShGetIconOfApp(
    LPCWSTR AppPath, 
    HICON   *Icon,
    HICON   *IconSm
) {
    BOOL            Result              = FALSE;
    HMODULE         hSkype              = NULL;

    HRESULT         hr                  = S_FALSE;
    IShellFolder*   pDesktop            = NULL;
    IShellFolder*   pFolder             = NULL;
    WCHAR           szFolder[MAX_PATH]  = L"";
    WCHAR           szFile[MAX_PATH]    = L"";
    LPITEMIDLIST    pidlFolder          = NULL;
    LPITEMIDLIST    pidlFile            = NULL;
    IExtractIcon*   pIcon               = NULL;

    WCHAR           szIconFile[MAX_PATH]= L"";
    UINT            cchMax              = MAX_PATH;
    int             iIndex              = 0;
    UINT            wFlags              = 0;

    HICON           hIcon               = NULL;
    HICON           hIconSm             = NULL;

    __try {
        if(AppPath == NULL 
        || wcslen(AppPath) == 0 
        || Icon == NULL) {
            __leave;
        }

        PszStringCopy(szFolder, 
                      _countof(szFolder), 
                      AppPath
                     );
        if(!PathRemoveFileSpecW(szFolder)) {
            __leave;
        }

        PszStringCopy(szFile, 
                      _countof(szFile), 
                      AppPath
                     );
        PathStripPathW(szFile);

        hr = SHGetDesktopFolder(&pDesktop);
        if(FAILED(hr)) {
            __leave;
        }

        hr = IShellFolder_ParseDisplayName(pDesktop, 
                                           NULL, 
                                           NULL, 
                                           szFolder, 
                                           NULL, 
                                           &pidlFolder, 
                                           NULL
                                          );
        if(FAILED(hr)) {
            __leave;
        }
        if(pidlFolder == NULL) {
            __leave;
        }

        hr = IShellFolder_BindToObject(pDesktop, 
                                       pidlFolder, 
                                       NULL, 
                                       &IID_IShellFolder, 
                                       (void **)&pFolder
                                      );
        if(FAILED(hr)) {
            __leave;
        }
        if(pFolder == NULL) {
            __leave;
        }

        hr = IShellFolder_ParseDisplayName(pFolder, 
                                           NULL, 
                                           NULL, 
                                           szFile, 
                                           NULL, 
                                           &pidlFile, 
                                           NULL
                                          );
        if(FAILED(hr)) {
            __leave;
        }
        if(pidlFolder == NULL) {
            __leave;
        }

        hr = IShellFolder_GetUIObjectOf(pFolder, 
                                        NULL, 
                                        1, 
                                        &pidlFile, 
                                        &IID_IExtractIconW, 
                                        NULL, 
                                        (void **)&pIcon
                                       );
        if(FAILED(hr)) {
            __leave;
        }
        if(pIcon == NULL) {
            __leave;
        }

        hr = IExtractIcon_GetIconLocation(pIcon, 
                                          GIL_FORSHELL, 
                                          szIconFile, 
                                          cchMax, 
                                          &iIndex, 
                                          &wFlags
                                         );
        if(FAILED(hr)) {
            __leave;
        }

        hr = IExtractIcon_Extract(pIcon, 
                                  szIconFile, 
                                  iIndex, 
                                  &hIcon, 
                                  NULL, 
                                  MAKELONG(64, 64)
                                 );
        if(SUCCEEDED(hr)) {
            *Icon = hIcon;
        }

        hr = IExtractIcon_Extract(pIcon, 
                                  szIconFile, 
                                  iIndex, 
                                  NULL, 
                                  &hIconSm, 
                                  MAKELONG(16, 16)
                                 );
        if(SUCCEEDED(hr)) {
            *IconSm = hIconSm;
        }

        Result = TRUE;
    }
    __finally {
        if(pIcon != NULL) {
            IExtractIcon_Release(pIcon);
        }

        if(pidlFile != NULL) {
            ILFree(pidlFile);
        }
        if(pidlFolder != NULL) {
            ILFree(pidlFolder);
        }

        if(pFolder != NULL) {
            IShellFolder_Release(pFolder);
        }
        if(pDesktop != NULL) {
            IShellFolder_Release(pDesktop);
        }

        if(hSkype != NULL) {
            FreeLibrary(hSkype);
        }
    }

    return Result;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader BitDefender
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions