unloading an unmanaged C++ add-in?

  • Thread starter Patrick Schmid [MVP]
  • Start date
P

Patrick Schmid [MVP]

I am trying to unload an unmanaged C++ Office 2007 add-in with code in
the add-in itself. In a managed add-in, this works without a problem,
but I can't get it to work with an unmanaged C++ one.
What I am trying to do is to set the Connect property of the Add in
Instance to false.
So the code for this is:
STDMETHOD(OnConnection)(IDispatch * Application,
AddInDesignerObjects::ext_ConnectMode ConnectMode,
IDispatch *AddInInst, SAFEARRAY **custom)
{
HRESULT hr = S_OK;

CComPtr<IDispatch> m_pAddInInstance;
IfFailGo(AddInInst->QueryInterface(__uuidof(IDispatch),
(LPVOID*)&m_pAddInInstance));
IfFailGo(m_pAddInInstance->QueryInterface(__uuidof(COMAddIn),
(void**)&addInInstance));
Error:
return hr;
}

With
protected:
COMAddIn * addInInstance;

---
Then I am trying to unload it using
addInInstance->put_Connect(false);
---
When I try this, the DLL is unloaded, followed by the unloading of
msvcr80d.dll and then Culture.dll
But then, I get a first-chance exception in the Office app (e.g.
Excel.exe): Access violation reading location ...
Followed by lots of more first-chance exception (all access violations),
but all for a different address. Eventually, I get a stack overflow.
Does anyone have any idea what I could be doing wrong?

Thanks,

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
P

Patrick Schmid [MVP]

I found a way around it. If I embed the put_Connect(VARIANT_FALSE) part
in a new thread and let the other thread return to Office, then it
works.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 

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