Inspectors event in VC++ ATL Programming

  • Thread starter Abdulla P.P via OfficeKB.com
  • Start date
A

Abdulla P.P via OfficeKB.com

ppabdu[AT]yahoo[DOT]com

Hi,

I would like to know how we can catch Inspector open and close events.
I tried it but i cannot register the event for an inspector(I think this is
due to the inspector object is NULL).
Also I faced same problem in ItemEvents.
No compile errror.only runtime error which popup a "send and don't send"
window.
I don't know what do.
Please help me.

Thanks,
Abdulla.P.P
 
D

Dmitry Streblechenko

You *really* need to post the relevant pieces of your code and indicate
where you get the unexpected results.

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

Abdulla P.P via OfficeKB.com

Hi Dmitry Streblechenko,

Sorry for inconvenience,I paste what i have done bellow.

I have addded a toolbar button and i can catch its click event no problems
at all.so i donot paste that part.

in Addin.h file i wrote:
Top of Addin.h file
extern _ATL_FUNC_INFO OnActiveInspectorInfo;

implement the class as
public IDispEventSimpleImpl<3,CAddin,&__uuidof(Outlook::InspectorEvents )>

In my class defenition i added a type declaration
typedef IDispEventSimpleImpl</*nID =*/ 3,CAddin, &__uuidof
(Outlook::InspectorEvents)> MyInspectorEvents;

sink entry info is like this :
SINK_ENTRY_INFO( 3,__uuidof(Outlook::InspectorEvents),/*dispid*/
0xf001,OnActive,&OnActiveInspectorInfo)

My event handler function is:
public void __stdcall OnActive(IDispatch * inspector);


OnConnection Method i put this code:
hr=MyInspectorEvents::DispEventAdvise((IDispatch*)m_spInspector);
if(FAILED(hr)) return hr;

OnDisconnection Method i put this code:
hr=MyInspectorEvents::DispEventUnadvise((IDispatch*)m_spInspector);
if(FAILED(hr)) return hr;

and I declare ispector object as :
private CComPtr<Outlook::_Inspector>m_spInspector;

In Addin.cpp i wrote:
on top:
_ATL_FUNC_INFO OnActiveInspectorInfo ={CC_STDCALL,VT_EMPTY,1,VT_DISPATCH};

then write the event handler as:
void __stdcall CAddin::OnActive(IDispatch * inspector)
{
MessageBox(NULL, "Active inspector event", "Outlook 2000", MB_OK);
}

Thats all my code.
The problem i have faced is on OnConnection method itself while advising
the inspector event.at that time a "Send and Don't send" window pop ups and
messages that "You have got a problem,sorry for inconvenience and send the
error report to Microsoft.. etc"
I think this is enough..


thanks,
bye
 
A

Abdulla P.P via OfficeKB.com

Hi Henry Gusakovsky,

As i told in my previous posting m_spInspector is declared as private
variable in the CAddin class.
private CComPtr<Outlook::_Inspector>m_spInspector;
Please help me .. I'm really fed up with it...

Thanks,
Abdulla.P.P
 
H

Henry Gusakovsky

It is only definition of that variable.

m_spInspector should point to the real object.

It can't be NULL.

because hr=MyInspectorEvents::DispEventUnadvise((IDispatch*)m_spInspector);
eventualy does the following:
(in your case)
pUnkCP: is your m_spInspector
pUnk: is pointer to your class implementing
IDispEventSimpleImpl<3,CAddin,&__uuidof(Outlook::InspectorEvents )> So it is
'this' pointer
iid: __uuidof(Outlook::InspectorEvents )
pdw: cookie for Unadvise.

ATLINLINE ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid,
LPDWORD pdw)
{
CComPtr<IConnectionPointContainer> pCPC;
CComPtr<IConnectionPoint> pCP;
HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer,
(void**)&pCPC);
if (SUCCEEDED(hRes))
hRes = pCPC->FindConnectionPoint(iid, &pCP);
if (SUCCEEDED(hRes))
hRes = pCP->Advise(pUnk, pdw);
return hRes;
}

So as you can see if m_spInspector is NULL this call will crash.
 
A

Abdulla P.P via OfficeKB.com

Hi Henry,
Thanks for ur reply.
I am also know that the problem is due to NULL value.I want to know that
how can I overcome that problem..When I advise the event in onConnection
method there will not be any active inspector.The ActiveInspector method of
Application object returns a NULL value.so i cannot advise the event.
I have to get an inspectors active event.so i have to register or advise
the event before the inspector is get activated..without an active
inspector i couldnot advise the event.(because ActiveInspector method of
Application object returns a NULL value).damn... what a problem it is..

My aim is that make a toobar button and a menu item on an active inspector.
After failing the attempt to get Inspectors active event I have tried to
get open event of an item.What to do,it also makes the same problem.

I have seen posting from some guys that they have succeeded to get
Inspectors active event.
Expects some help..it is very urgent to me

Thanks,
Abdulla.P.P
 
H

Heinz-Josef Bomanns

Hi Abdulla,
When I advise the event in onConnection
method there will not be any active inspector.

I'm no C++ programmer, so i can't give you any code samples. But in
generell you first need to monitor the Inspectors collection like this
in VB:

Dim WithEvents colInsp as Outlook.Inspectors

After that you can catch a "NewInspector" event via "colInsp". It is
fired if a new inspector is opend. The new Inspector object is passed
as a parameter "Inspector". With this you can initialize another
object variable like this:

Dim WithEvents objInsp as Outlook.Inspector

Any event of this new Inspector object like "Activate" or "Close" can
then be catched via "objInsp".

Hope this helps a little bit...
 
H

Heinz-Josef Bomanns

Hi Abdulla,
Dim WithEvents objInsp as Outlook.Inspector

Sorry, forgott one instruction you must add to "NewInspector" event:

Set objInsp = Inpector

Then:
Any event of this new Inspector object like "Activate" or "Close" can
then be catched via "objInsp".
 
H

Henry Gusakovsky

You need to advise for Outlook::InspectorsEvents in the
_Application::Inspectors collection.
Event OnNewInspector is called when some inspector is opened.

So in OnNewInspector event handler you can advise for
Outlook::InspectorEvents.

If in OnConnect _Application::Inspectors is not empty you can advise for
every inspector in this collection.
 
A

Abdulla P.P via OfficeKB.com

Hi All,
Thanks Henry Gusakovsky for ur help finally i have got it.
Thanks for all they have tried to help me.

regards Abdulla.P.P
 
J

Jayashree Sekar

Hi Henry,

My requiremet is similar to Abdulla's. I need to include a custom toolbar
with some buttons in all inspectors which are of message class 'IPM.Post'. I
use VC++ in my project.

First, I tried handling OnNewInspector event in which I tried inserting my
custom toolbar & advising the commandBar button event. This worked fine for
the first inspector(i.e. when I click new MailMessage for the first time) &
the problem raised when I tried opening another mail message. Technically
the problem was, I was not able to advise the commandBar button event for
the new inspector when it was already advised for the previous inspector.

After surfing the net, I read that my task can be very well accomplished if
I handle the 'Activate' & 'DeActivate' events of 'InspectorEvents'.

But to handle this 'Activate' & 'DeActivate' events of 'InspectorEvents', I
again have to advise them in 'OnNewInspector' which again gives me the same
problem.

Please help me out. This a very urgent requirement & I have already spent
more time on exploring this.

Awaiting for your help,
Shree

url:http://www.ureader.com/msg/1079162.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top