D
davidb
Hi,
i try building a Outlook Addin with VStudio .net 2003. Its a simple
Button, i want that button to call another Application later with
ShellExecute. Now my Goal is to show it and Pop up a MessageBox.
Compiles fine but the MessageBox dont Pop up ! The Box itself Works, i
get no error on Hresult, i tested the Message in OnConnection ! Any
Ideas ? Someone Told me the third Param of the SINK_ENTRY_INFO has to
be 0x01 and is addicted to what event occured !?
here's my Code (i made it ahalf with the Assistant):
//-----------------------------------------
// ## Connect.cpp #########
//-----------------------------------------
// Connect.cpp : Implementation of CConnect
#include "stdafx.h"
#include "AddIn.h"
#include "Connect.h"
extern CAddInModule _AtlModule;
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such
as:
// 1) You moved this project to a computer other than which is was
originally created on.
// 2) You chose 'Yes' when presented with a message asking if you
wish to remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the
MyAddin21Setup project
// by right clicking the project in the Solution Explorer, then
choosing install.
// CConnect
STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication,
AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch
*pAddInInst, SAFEARRAY ** /*custom*/ )
{
pApplication->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pAddInInstance);
CComPtr<Office::_CommandBars> spCmdBars;
CComPtr<Office::CommandBar> spCmdBar;
CComPtr<Outlook::_Explorer> spExplorer;
CComPtr<Office::_CommandBarButton> m_spButton;
CComPtr<Outlook::_Application> m_spApp;
// BtnEvent Handler
pHdl = new CEventHdl();
pHdl->AddRef();
// QueryInterface() for _Application
CComQIPtr <Outlook::_Application> spApp(pApplication);
ATLASSERT(spApp);
//make a copy of our Application Object
m_spApp = spApp;
//get the ActiveExplorer Object
//each window is called as an Explorer in Outlook
//so our current viewing wimdow when Outlook starts is Explorer
//so get the object
spApp->ActiveExplorer(&spExplorer);
// get the CommandBars interface that represents Outlook's
//toolbars & menu
//items
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
//give a name for our newly created Toolbar
CComVariant vName("Test Toolbar");
//obtain a reference to CommandBar Control
CComPtr <Office::CommandBar> spNewCmdBar;
//sepcify in which position our button to be placed.
//for us it is 1st position
CComVariant vPos(1);
CComVariant vTemp(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
//add the toolbar
spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
//to add a button to our toolbar we have to get a reference
//to CommandBarControls Control.Consider Button as a Command
//BarControl.For Further details,refer Microsoft Outlook
//Object Model.
CComPtr < Office::CommandBarControls> spBarControls;
spBarControls = spNewCmdBar->GetControls();
ATLASSERT(spBarControls);
//MsoControlType::msoControlButton = 1
CComVariant vToolBarType(1);
//show the toolbar
CComVariant vShow(VARIANT_TRUE);
CComPtr < Office::CommandBarControl> spNewBar;
//now add the CommandBarControls of type Button
spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty,
vShow);
ATLASSERT(spNewBar);
_bstr_t bstrNewCaption(OLESTR("Test"));
_bstr_t bstrTipText(OLESTR("Open Test"));
//now comes the work of adding the Button to our CommandBarControl
//get a reference to CommandBarButton
CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
ATLASSERT(spCmdButton);
//assign the properties
spCmdButton->put_Style(Office::msoButtonIconAndCaption);
spCmdButton->PutVisible(VARIANT_TRUE);
spCmdButton->PutCaption(OLESTR("Test"));
spCmdButton->PutEnabled(VARIANT_TRUE);
spCmdButton->PutTooltipText(OLESTR("Open Test"));
spCmdButton->PutTag(OLESTR("Test"));
spCmdButton->put_FaceId(1845); // Billard Ball (8) ?
//put into picture the New CommandBarControl too
spNewCmdBar->PutVisible(VARIANT_TRUE);
m_spButton = spCmdButton;
pHdl->DispEventAdvise((IDispatch*)spCmdButton,&__uuidof(Office::_CommandBarButtonEvents));
return S_OK;
}
STDMETHODIMP
CConnect::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode
/*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
pHdl->DispEventUnadvise((IDispatch*)m_spButton,&DIID__CommandBarButtonEvents);
m_pApplication = NULL;
return S_OK;
}
STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
//-----------------------------------------
// ## Connect.h ###########
//-----------------------------------------
// Connect.h : Declaration of the CConnect
#pragma once
#include "resource.h" // main symbols
static _ATL_FUNC_INFO OnClickButtonInfo =
{
CC_STDCALL, // Calling convention.
VT_EMPTY, // Return type.
2, // Number of arguments.
{ VT_DISPATCH, VT_BOOL|VT_BYREF } // Argument types.
};
class CEventHdl : public IDispEventSimpleImpl<1, CEventHdl,
&__uuidof(Office::_CommandBarButtonEvents)>
{
public:
BEGIN_SINK_MAP(CEventHdl)
SINK_ENTRY_INFO(1,__uuidof(Office::_CommandBarButtonEvents), 0x01,
OnClickButton, &OnClickButtonInfo)
END_SINK_MAP()
STDMETHOD(OnClickButton)(IDispatch* Ctrl, VARIANT_BOOL* pbResult)
{
*pbResult = VARIANT_FALSE;
MessageBox(NULL, _T("CEventHdl"), _T("Test"), MB_OK);
return S_OK;
}
};
// CConnect
class ATL_NO_VTABLE CConnect :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CConnect, &CLSID_Connect>,
public
IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2,&AddInDesignerObjects::IID__IDTExtensibility2,
&AddInDesignerObjects::LIBID_AddInDesignerObjects, 1, 0>
{
public:
CConnect()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_NOT_AGGREGATABLE(CConnect)
BEGIN_COM_MAP(CConnect)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
//IDTExtensibility2 implementation:
STDMETHOD(OnConnection)(IDispatch * Application,
AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch
*AddInInst, SAFEARRAY **custom);
STDMETHOD(OnDisconnection)(AddInDesignerObjects::ext_DisconnectMode
RemoveMode, SAFEARRAY **custom );
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom );
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom );
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom );
CEventHdl *pHdl;
CComPtr<Office::_CommandBarButton> m_spButton;
CComPtr<IDispatch> m_pApplication;
CComPtr<IDispatch> m_pAddInInstance;
};
OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)
i try building a Outlook Addin with VStudio .net 2003. Its a simple
Button, i want that button to call another Application later with
ShellExecute. Now my Goal is to show it and Pop up a MessageBox.
Compiles fine but the MessageBox dont Pop up ! The Box itself Works, i
get no error on Hresult, i tested the Message in OnConnection ! Any
Ideas ? Someone Told me the third Param of the SINK_ENTRY_INFO has to
be 0x01 and is addicted to what event occured !?
here's my Code (i made it ahalf with the Assistant):
//-----------------------------------------
// ## Connect.cpp #########
//-----------------------------------------
// Connect.cpp : Implementation of CConnect
#include "stdafx.h"
#include "AddIn.h"
#include "Connect.h"
extern CAddInModule _AtlModule;
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such
as:
// 1) You moved this project to a computer other than which is was
originally created on.
// 2) You chose 'Yes' when presented with a message asking if you
wish to remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the
MyAddin21Setup project
// by right clicking the project in the Solution Explorer, then
choosing install.
// CConnect
STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication,
AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch
*pAddInInst, SAFEARRAY ** /*custom*/ )
{
pApplication->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pApplication);
pAddInInst->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pAddInInstance);
CComPtr<Office::_CommandBars> spCmdBars;
CComPtr<Office::CommandBar> spCmdBar;
CComPtr<Outlook::_Explorer> spExplorer;
CComPtr<Office::_CommandBarButton> m_spButton;
CComPtr<Outlook::_Application> m_spApp;
// BtnEvent Handler
pHdl = new CEventHdl();
pHdl->AddRef();
// QueryInterface() for _Application
CComQIPtr <Outlook::_Application> spApp(pApplication);
ATLASSERT(spApp);
//make a copy of our Application Object
m_spApp = spApp;
//get the ActiveExplorer Object
//each window is called as an Explorer in Outlook
//so our current viewing wimdow when Outlook starts is Explorer
//so get the object
spApp->ActiveExplorer(&spExplorer);
// get the CommandBars interface that represents Outlook's
//toolbars & menu
//items
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
//give a name for our newly created Toolbar
CComVariant vName("Test Toolbar");
//obtain a reference to CommandBar Control
CComPtr <Office::CommandBar> spNewCmdBar;
//sepcify in which position our button to be placed.
//for us it is 1st position
CComVariant vPos(1);
CComVariant vTemp(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
//add the toolbar
spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
//to add a button to our toolbar we have to get a reference
//to CommandBarControls Control.Consider Button as a Command
//BarControl.For Further details,refer Microsoft Outlook
//Object Model.
CComPtr < Office::CommandBarControls> spBarControls;
spBarControls = spNewCmdBar->GetControls();
ATLASSERT(spBarControls);
//MsoControlType::msoControlButton = 1
CComVariant vToolBarType(1);
//show the toolbar
CComVariant vShow(VARIANT_TRUE);
CComPtr < Office::CommandBarControl> spNewBar;
//now add the CommandBarControls of type Button
spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty,
vShow);
ATLASSERT(spNewBar);
_bstr_t bstrNewCaption(OLESTR("Test"));
_bstr_t bstrTipText(OLESTR("Open Test"));
//now comes the work of adding the Button to our CommandBarControl
//get a reference to CommandBarButton
CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
ATLASSERT(spCmdButton);
//assign the properties
spCmdButton->put_Style(Office::msoButtonIconAndCaption);
spCmdButton->PutVisible(VARIANT_TRUE);
spCmdButton->PutCaption(OLESTR("Test"));
spCmdButton->PutEnabled(VARIANT_TRUE);
spCmdButton->PutTooltipText(OLESTR("Open Test"));
spCmdButton->PutTag(OLESTR("Test"));
spCmdButton->put_FaceId(1845); // Billard Ball (8) ?
//put into picture the New CommandBarControl too
spNewCmdBar->PutVisible(VARIANT_TRUE);
m_spButton = spCmdButton;
pHdl->DispEventAdvise((IDispatch*)spCmdButton,&__uuidof(Office::_CommandBarButtonEvents));
return S_OK;
}
STDMETHODIMP
CConnect::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode
/*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
pHdl->DispEventUnadvise((IDispatch*)m_spButton,&DIID__CommandBarButtonEvents);
m_pApplication = NULL;
return S_OK;
}
STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}
//-----------------------------------------
// ## Connect.h ###########
//-----------------------------------------
// Connect.h : Declaration of the CConnect
#pragma once
#include "resource.h" // main symbols
static _ATL_FUNC_INFO OnClickButtonInfo =
{
CC_STDCALL, // Calling convention.
VT_EMPTY, // Return type.
2, // Number of arguments.
{ VT_DISPATCH, VT_BOOL|VT_BYREF } // Argument types.
};
class CEventHdl : public IDispEventSimpleImpl<1, CEventHdl,
&__uuidof(Office::_CommandBarButtonEvents)>
{
public:
BEGIN_SINK_MAP(CEventHdl)
SINK_ENTRY_INFO(1,__uuidof(Office::_CommandBarButtonEvents), 0x01,
OnClickButton, &OnClickButtonInfo)
END_SINK_MAP()
STDMETHOD(OnClickButton)(IDispatch* Ctrl, VARIANT_BOOL* pbResult)
{
*pbResult = VARIANT_FALSE;
MessageBox(NULL, _T("CEventHdl"), _T("Test"), MB_OK);
return S_OK;
}
};
// CConnect
class ATL_NO_VTABLE CConnect :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CConnect, &CLSID_Connect>,
public
IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2,&AddInDesignerObjects::IID__IDTExtensibility2,
&AddInDesignerObjects::LIBID_AddInDesignerObjects, 1, 0>
{
public:
CConnect()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_NOT_AGGREGATABLE(CConnect)
BEGIN_COM_MAP(CConnect)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
//IDTExtensibility2 implementation:
STDMETHOD(OnConnection)(IDispatch * Application,
AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch
*AddInInst, SAFEARRAY **custom);
STDMETHOD(OnDisconnection)(AddInDesignerObjects::ext_DisconnectMode
RemoveMode, SAFEARRAY **custom );
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom );
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom );
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom );
CEventHdl *pHdl;
CComPtr<Office::_CommandBarButton> m_spButton;
CComPtr<IDispatch> m_pApplication;
CComPtr<IDispatch> m_pAddInInstance;
};
OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)