A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 12th 06, 04:25 PM posted to microsoft.public.outlook.program_addins
davidb
external usenet poster
 
Posts: 2
Default Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise

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);

CComPtrOffice::_CommandBars spCmdBars;
CComPtrOffice::CommandBar spCmdBar;
CComPtrOutlook::_Explorer spExplorer;
CComPtrOffice::_CommandBarButton m_spButton;
CComPtrOutlook::_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::ex t_DisconnectMode
/*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
pHdl-DispEventUnadvise((IDispatch*)m_spButton,&DIID__C ommandBarButtonEvents);
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 IDispEventSimpleImpl1, CEventHdl,
&__uuidof(Office::_CommandBarButtonEvents)
{
public:

BEGIN_SINK_MAP(CEventHdl)
SINK_ENTRY_INFO(1,__uuidof(Office::_CommandBarButt onEvents), 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 CComObjectRootExCComSingleThreadModel,
public CComCoClassCConnect, &CLSID_Connect,
public
IDispatchImplAddInDesignerObjects::_IDTExtensibil ity2,&AddInDesignerObjects::IID__IDTExtensibility2 ,
&AddInDesignerObjects::LIBID_AddInDesignerObjec ts, 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::IDTExten sibility2)
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::e xt_DisconnectMode
RemoveMode, SAFEARRAY **custom );
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom );
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom );
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom );

CEventHdl *pHdl;
CComPtrOffice::_CommandBarButton m_spButton;
CComPtrIDispatch m_pApplication;
CComPtrIDispatch m_pAddInInstance;

};

OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)

Ads
  #2  
Old June 12th 06, 06:13 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise

Make sure spCmdButton is alive at all times (make it a class member).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"davidb" wrote in message
oups.com...
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);

CComPtrOffice::_CommandBars spCmdBars;
CComPtrOffice::CommandBar spCmdBar;
CComPtrOutlook::_Explorer spExplorer;
CComPtrOffice::_CommandBarButton m_spButton;
CComPtrOutlook::_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::ex t_DisconnectMode
/*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
pHdl-DispEventUnadvise((IDispatch*)m_spButton,&DIID__C ommandBarButtonEvents);
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 IDispEventSimpleImpl1, CEventHdl,
&__uuidof(Office::_CommandBarButtonEvents)
{
public:

BEGIN_SINK_MAP(CEventHdl)
SINK_ENTRY_INFO(1,__uuidof(Office::_CommandBarButt onEvents), 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 CComObjectRootExCComSingleThreadModel,
public CComCoClassCConnect, &CLSID_Connect,
public
IDispatchImplAddInDesignerObjects::_IDTExtensibil ity2,&AddInDesignerObjects::IID__IDTExtensibility2 ,
&AddInDesignerObjects::LIBID_AddInDesignerObjec ts, 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::IDTExten sibility2)
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::e xt_DisconnectMode
RemoveMode, SAFEARRAY **custom );
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom );
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom );
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom );

CEventHdl *pHdl;
CComPtrOffice::_CommandBarButton m_spButton;
CComPtrIDispatch m_pApplication;
CComPtrIDispatch m_pAddInInstance;

};

OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)



  #3  
Old June 13th 06, 03:53 AM posted to microsoft.public.outlook.program_addins
[email protected]
external usenet poster
 
Posts: 1
Default Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise

Avoid typing the same text again and again
Stop wasting your time on mouse movements
Open favorite web pages with a single hotkey press
Record keystrokes and play them back with a single hotkey press
------------------------------
http://www30.webSamba.com/SmartStudio
------------------------------
EnergyKey Save yourself from repetitive tasks

  #4  
Old June 13th 06, 08:31 AM posted to microsoft.public.outlook.program_addins
davidb
external usenet poster
 
Posts: 2
Default Getting no Events ! - IDispEventSimpleImpl , DispEventAdvise

Dmitry Save'd the day ! Thank you !

The Problem as follows:
First I made my Button like this:

//---------------------------
// Connect.cpp
//---------------------------

CComQIPtr Office::_CommandBarButton spCmdButton(spNewBar);

m_spButton = spCmdButton;

pHdl-DispEventAdvise((IDispatch*)m_spButton,&__uuidof( Office::_CommandBarButtonEvents));

//---------------------------
// Connect.h
//---------------------------

CComPtrOffice::_CommandBarButton m_spButton;

Now I make it like this:

//---------------------------
// Connect.cpp
//---------------------------

spCmdButton = spNewBar;

pHdl-DispEventAdvise((IDispatch*)spCmdButton,&__uuidof (Office::_CommandBarButtonEvents));

//---------------------------
// Connect.h
//---------------------------

CComPtrOffice::_CommandBarButton spCmdButton;

---------------------------------
Greetings, Dave
---------------------------------

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Events Theresa Smallwood Outlook - Using Forms 0 May 9th 06 04:07 PM
Custom Events Theresa Smallwood Add-ins for Outlook 0 May 9th 06 04:07 PM
Linking events? Marc Outlook - Calandaring 1 March 14th 06 02:40 PM
Why do events dissapear Melsamer Outlook - Calandaring 0 February 27th 06 02:11 PM
Events not always triggered Jim Burke in Novi Outlook and VBA 1 January 30th 06 06:36 AM


All times are GMT +1. The time now is 09:32 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.