How to develop IE Addons using VC++ and ATL - Video Tutorial

Rate this article
5.00 out of 5
It is fact that developing a very basic IE Add-in/Plug-in in the early stages of any bodies programming career is always a difficult task as he or she needs to get familiar with some of the VC++ libraries which includes some of the difficult libraries like Active Template Library (ATL).  This IE Addin video tutorials was created just to reduce that learning curve. I hope the accompanying video and source code will guide you in working with IE Addin creation and will reduce the time to learn the development of IE Addons. If you have any questions, please do post in the comments section of this article.

     

Download the source code from the link below.

Source Code

MyPlugins.cpp 

// MyPlugins.cpp : Implementation of DLL Exports.


#include "stdafx.h"
#include "resource.h"
#include "MyPlugins.h"
#include "dlldatax.h"


class CMyPluginsModule : public CAtlDllModuleT< CMyPluginsModule >
{
public :
DECLARE_LIBID(LIBID_MyPluginsLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MYPLUGINS, "{6C16343B-74A6-4677-9EFD-AB58FDB3039E}")
};

CMyPluginsModule _AtlModule;


#ifdef _MANAGED
#pragma managed(push, off)
#endif

// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
#ifdef _MERGE_PROXYSTUB
    if (!PrxDllMain(hInstance, dwReason, lpReserved))
        return FALSE;
#endif
hInstance;
    return _AtlModule.DllMain(dwReason, lpReserved); 
}

#ifdef _MANAGED
#pragma managed(pop)
#endif




// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
#ifdef _MERGE_PROXYSTUB
    HRESULT hr = PrxDllCanUnloadNow();
    if (hr != S_OK)
        return hr;
#endif
    return _AtlModule.DllCanUnloadNow();
}


// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
#ifdef _MERGE_PROXYSTUB
    if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
        return S_OK;
#endif
    return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}


// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer();
#ifdef _MERGE_PROXYSTUB
    if (FAILED(hr))
        return hr;
    hr = PrxDllRegisterServer();
#endif
return hr;
}


// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
HRESULT hr = _AtlModule.DllUnregisterServer();
#ifdef _MERGE_PROXYSTUB
    if (FAILED(hr))
        return hr;
    hr = PrxDllRegisterServer();
    if (FAILED(hr))
        return hr;
    hr = PrxDllUnregisterServer();
#endif
return hr;
}

Plugin.cpp 

// Plugin.cpp : Implementation of CPlugin

#include "stdafx.h"
#include "Plugin.h"


// CPlugin

STDMETHODIMP CPlugin::SetSite(IUnknown *pUnkSite)
{
    if (pUnkSite != NULL)
    {
        CComQIPtr<IServiceProvider> sp = pUnkSite;
        HRESULT hr = sp->QueryService(IID_IWebBrowserApp,
            IID_IWebBrowser2, (void**)&m_spWebBrowser);
        hr = sp->QueryInterface(IID_IOleCommandTarget,
            (void**)&m_spTarget);
    }
    else
    { 
        m_spWebBrowser.Release();
        m_spTarget.Release();
    }
    return IObjectWithSiteImpl<CPlugin>::SetSite(pUnkSite);
}

STDMETHODIMP CPlugin::Exec(
    const GUID *pguidCmdGroup, DWORD nCmdID,
    DWORD nCmdExecOpt, VARIANTARG *pvaIn, VARIANTARG *pvaOut)
{
    MessageBox(NULL, _T("Hello, World!"), _T("Greetings"), 0);
    return S_OK;
}
STDMETHODIMP CPlugin::QueryStatus(
    const GUID* pguidCmdGroup, ULONG cCmds,
    OLECMD prgCmds[], OLECMDTEXT* pCmdText)
{
    int i;
    for (i=0; i<((int) cCmds); i++)
        prgCmds[i].cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
    return  S_OK;
}


Surce Code

Joined Date :14-Nov-2012
Articles
Posted
60
Messages
Posted
3

KTS InfoTech Training division offers various short-term programming courses for Students and Professionals who are looking for a bright career in the field of Software development.

The programming video tutorials presented in this web site are taken from some of the training sessions conducted by KTS InfoTech.

You can also learn the Programming packages through Internet directly form our English Speaking Technical experts at an affordable rate.

For more details click here and submit your training requirements.




   
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments

TekTipsDownload
GateExam
Academic Projects
TekTipsExperts



 
Site optimized for IE7, 1280 X 768 and above. Copyright © 2010 - 2018 KTS InfoTech
Site Developed Using KTS WebCloud