Outlook Controls on custom Outlook forms never being destroyed

Joined
May 13, 2008
Messages
1
Reaction score
0
Hi,

We have an Outlook add-in built in C++/COM. The add-in uses custom Outlook forms, on which we have placed ActiveX controls from a separate MFC DLL. We have imported the MFC DLL into the add-in DLL, so that we have access to the ActiveX controls in the add-in code.

The code inside the add-in which initializes an extra tab for our custom form, and creates the control, looks something like this:

OI::pagesPtr pPages;
if (m_pCustomControl == NULL &&
SUCCEEDED(m_pInspector->raw_ShowFormPage(L"Custom")) &&
(pPages = m_pInspector->ModifiedFormPages) != NULL)
{
Forms::_UserFormPtr pPage = pPages->Item(L"Custom");
if (pPage)
{
Forms::IControlPtr pControl = pPage->Controls->Item(L"Custom1");
if (pControl)
{
// Save a reference to the Custom Control.
m_pCustomControl = pControl;
}
}
}

... where m_pCustomControl is a smart pointer to our ActiveX control.

It is during the pPages->Item() call that our ActiveX control's constructor is called. From what I understand, the control should also be destroyed automatically when the Inspector is closed (and I certainly can't find any methods to do it manually)... but it's not. So, for every custom appointment a user opens, we leak memory.

The interesting thing is that our code was different for a while - the guy who implemented it didn't realize that he could import the MFC DLL, so we were using raw Invoke()s to talk to the ActiveX controls. Our m_pCustomControl was just a Forms::IControlPtr, rather than a pointer to the custom control. What we saw THERE was that m_pCustomControl didn't change throughout the lifetime of the appointment, but the underlying ActiveX control was deleted and recreated every time we hid and reshowed the custom tab (which caused its own set of problems). I don't know exactly what the magic difference was, because I can't reproduce the behavior by simply making my m_pCustomControl a Forms::IControlPtr in our new code. But SOMEthing is obviously being handled differently in the schema we use now.

Any thoughts would be greatly appreciated! I'm sure I can come up with a kludgy way to delete the custom control out from under the Inspector, but that feels dangerous to me. And if the control isn't being destroyed, maybe other things further upstream aren't either....

Thanks!



 

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