Accessing Application.Explorers.Count property calls Release() ??

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I'm writing an Outlook COM Add-in using C++. During the
OnStartupComplete event I get the Application.Explorers object, which
I am able to work with for the most part. I can setup event sinks for
it, etc.

The problem comes up when I check the "Count" property of the
Explorers object. It seems like an IUnknown::Release() call is also
being made. I wrote some quick code to check this, like:

before = Explorers->AddRef();
c = Explorers->GetCount();
after = Explorers->Release();

The call to AddRef() before I access the Count property returns 3. I
would then expect the Release() call to return 2, however it doesn't,
it returns 1.

Is this expected? If so, how do I know if accessing a property is
going to have this affect, is there a list somewhere?

On another note, are there any good books on writing an Outlook COM
Add-in using just C++ without MFC/ATL/etc? I'm doing pretty good so
far, but I'm worried about memory leaks due to these AddRef() and
Release() calls. I'm doing things at a very low level, without
importing type libraries or anything, just working at the IDispatch
level for everything. For me this seems easier, but I must be the
only one going this route, because I'm having trouble finding any
examples. Even the "C++ without MFC/ATL" MSGDUMP2000 example imports
the type libraries. I have no urge to work with those huge header
files or have to deal with differences of how each compiler builds a
type library header.
 
I figured it out myself, just a bone-head move. I wasn't clearing the
VARIANT type variable before using it again, so somewhere inside the
OLE or Outlook code it must have been clearing it for me, which
explains the Release() call on the object.
 
Back
Top