Starting New Project C++ ATL

Developing your first project in C++

  1. Open Visual Studio 2008
  2. ATL Project Wizard: Select File/New/Project and choose ATL Project with the name MyFirstWLMailProject
  3. Press Next, Select Dynamic-link library (DLL) and press Finish.
  4. The project is initialized with an ATL code stub.
  5. In the "Class View" of MyFirstWLMailProject:
    1. Select Add/Class
    2. Choose ATL/ATL Simple Object
    3. Press Add
    4. Choose MyFirstAddon as a name, then Finish.
    5. This will generate an stub for your COM Object.
  6. Add/Modify the following code to MyFirstAddon.h
  7. Before the CMyFirstAddon class definition:
extern _ATL_FUNC_INFO NoParamInfo;
extern _ATL_FUNC_INFO OneLongParamInfo;
extern _ATL_FUNC_INFO TwoLongParamInfo;
extern _ATL_FUNC_INFO FourLongParamInfo;

  1.   
     9. Modify class definition and add some typedefs

class ATL_NO_VTABLE CMyFirstAddon :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CMyFirstAddon, &CLSID_MyFirstAddon>,
public IDispatchImpl<IMyFirstAddon, &IID_IMyFirstAddon, &LIBID_MyFirstWLMailProjectLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
// WLMailApi Events
public IDispEventSimpleImpl<1, CMyFirstAddon, &__uuidof(NktWLMailApiInit::IWLMailApiInitEvents)>,
public IDispEventSimpleImpl<2, CMyFirstAddon, &__uuidof(NktWLMailApi::IWLMailApiEvents)>
{
public:
typedef IDispEventSimpleImpl<1, CMyFirstAddon, &__uuidof(NktWLMailApiInit::IWLMailApiInitEvents)> _WLMailApiInitEvents;
typedef IDispEventSimpleImpl<2, CMyFirstAddon, &__uuidof(NktWLMailApi::IWLMailApiEvents)> _WLMailApiEvents;

  1.  
   10. Add SINK MAP and change OnInit, FinalConstruct, FinalRelease definitions

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_SINK_MAP(CMyFirstAddon)
SINK_ENTRY_INFO(1, __uuidof(NktWLMailApiInit::IWLMailApiInitEvents), 0x0001, OnInit, &NoParamInfo)
END_SINK_MAP()

//------------------------------------------------------------------//
// Init event, called when OEAPI is up
STDMETHOD(OnInit)();

HRESULT FinalConstruct();

void FinalRelease();

  1.   
   11. Add m_init class variable

private:
CComPtr<IWLMailApiInit> m_init;

  1.  
   12. Add/Modify the following code to MyFirstAddon.cpp. It adds the following functions:
    1. FinalConstruct: Called after the object is created.
    2. FinalRelease: Called after the object is destroyed.
    3. OnInit: Called when the plugin is loaded. In this example we add a MessageBox for notification.
_ATL_FUNC_INFO NoParamInfo = { CC_STDCALL, VT_EMPTY, 0 };
_ATL_FUNC_INFO OneLongParamInfo = { CC_STDCALL, VT_EMPTY, 1, { VT_INT } };
_ATL_FUNC_INFO TwoLongParamInfo = { CC_STDCALL, VT_EMPTY, 2, { VT_INT, VT_INT } };
_ATL_FUNC_INFO FourLongParamInfo = { CC_STDCALL, VT_EMPTY, 4, { VT_INT, VT_INT, VT_INT, VT_INT } };

// CMyFirstAddon
HRESULT CMyFirstAddon::FinalConstruct()
{
// create oeapi init notification object
HRESULT hr = m_init.CoCreateInstance(CLSID_WLMailApiInit); //, NULL, CLSCTX_INPROC_SERVER);
if(SUCCEEDED(hr))
{
_WLMailApiInitEvents::DispEventAdvise((IUnknown*)m_init, &__uuidof(IWLMailApiInitEvents));
}

return S_OK;
}

void CMyFirstAddon::FinalRelease()
{
_WLMailApiInitEvents::DispEventUnadvise((IUnknown*)m_init);
m_init = NULL;
}

STDMETHODIMP CMyFirstAddon::OnInit()
{
MessageBox(NULL, _T("OnInit() called"), _T("MyFirstAddon"), MB_OK|MB_SYSTEMMODAL);

return S_OK;
}

  1.  
   13. Register the Windows Live Mail Plugin adding the following registry key at the end of MyFirstAddon.rgs

HKCU
{
NoRemove Software
{
NoRemove Nektra
{
NoRemove WLMailAPi
{
NoRemove Plugins
{
val MyFirstWLMailProject = s 'MyFirstWLMailProject.MyFirstAddon'
}
}
}
}
}

  1.  
   14. Now Start the project (F5)

   15. If the "Executable For Debug Session" appears choose the Windows Live Mail executable file name (i.e.: C:\Program Files\Windows Live\Mail\wlmail.exe or C:\Program Files (x86)\Windows Live\Mail\wlmail.exe)
Comments