Click here to Skip to main content
15,884,473 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 "SkypeUtils.h"
#include "ShUtils.h"
#include "MemMgr.h"
#include "StringMgr.h"

//  MAJOR.minor string version length
static const int kMaxMmVersionLength = 32;

VOID
Skype_GetAppInfo(
    LPWSTR  *AppPath, 
    HICON   *Icon,
    HICON   *IconSm
) {
    LONG    lResult             = 0;
    HKEY    hkSkype             = NULL;
    WCHAR   SkypePath[MAX_PATH] = L"";
    DWORD   cbPath              = 0;
    DWORD   dwType              = REG_NONE;

    HICON   hIcon               = NULL;
    HICON   hIconSm             = NULL;

    __try {
        lResult = RegOpenKeyExW(HKEY_CURRENT_USER, 
                                L"Software\\Skype\\Phone", 
                                0, 
                                KEY_READ, 
                                &hkSkype
                               );
        if(lResult != ERROR_SUCCESS) {
            __leave;
        }
        cbPath = _countof(SkypePath) * sizeof(WCHAR);
        lResult = RegQueryValueExW(hkSkype, 
                                   L"SkypePath", 
                                   NULL, 
                                   &dwType, 
                                   (LPBYTE)&SkypePath[0], 
                                   &cbPath
                                  );
        if(lResult != ERROR_SUCCESS) {
            __leave;
        }
        if(dwType != REG_SZ) {
            __leave;
        }
        if(wcslen(SkypePath) == 0) {
            __leave;
        }
    }
    __finally {
        if(hkSkype != NULL) {
            RegCloseKey(hkSkype);
        }
    }

    if(SzStringLength(SkypePath) != 0) {
        PszStringDup(AppPath, 
                     SkypePath
                    );
    }

    //  get icon from Skype directly first
    if(SzStringLength(SkypePath) != 0) {
        HMODULE hSkype     = NULL;
        HICON   hIconLarge = NULL;
        HICON   hIconSmall = NULL;

        __try {
            hSkype = LoadLibraryExW(SkypePath, 
                                    NULL, 
                                    LOAD_LIBRARY_AS_DATAFILE
                                   );
            if(hSkype == NULL) {
                __leave;
            }

            hIconLarge = (HICON)LoadImageW(hSkype, 
                                           L"MAINICON", 
                                           IMAGE_ICON, 
                                           32, 
                                           32, 
                                           LR_LOADTRANSPARENT | LR_VGACOLOR
                                          );
            if(hIconLarge != NULL) {
                *Icon = hIconLarge;
            }

            hIconSmall = (HICON)LoadImageW(hSkype, 
                                           L"MAINICON", 
                                           IMAGE_ICON, 
                                           16, 
                                           16, 
                                           LR_LOADTRANSPARENT | LR_VGACOLOR
                                          );
            if(hIconSmall != NULL) {
                *IconSm = hIconSmall;
            }
        }
        __finally {
            if(hSkype != NULL) {
                FreeLibrary(hSkype);
            }
        }
    }

    //  icon
    if(*Icon == NULL || *IconSm == NULL) {
        if(ShGetIconOfApp(*AppPath, 
                          &hIcon, 
                          &hIconSm
                         )) {
            *Icon   = hIcon;
            *IconSm = hIconSm;
        }
    }

    return;
}

VOID
Skype_DeleteAvatarFile(LPVOID pvFileName) {
    if(pvFileName != NULL) {
        (VOID)DeleteFileW((LPCWSTR)pvFileName);
    }
}

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