Hi all;
Ok, here's the solution. Use the ConnectProxy.h I have listed below. This
will list out errors calling the managed add-in code.
BTW - not to look a gift horse in the mouth. And the add-in shim is a very
useful piece of code. But it strikes me as not of production quality - both
in that it silently errors out everywhere and it's extensive use of goto's.
thanks - dave
ConnectProxy.h:
// ConnectProxy.h : Declaration of the CConnectProxy
#pragma once
#include "resource.h" // main symbols
#include "COMAddInShim.h"
#include "DisplayError.h"
// CConnectProxy
class ATL_NO_VTABLE CConnectProxy :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CConnectProxy, &CLSID_ConnectProxy>,
public IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2,
&AddInDesignerObjects::IID__IDTExtensibility2,
&AddInDesignerObjects::LIBID_AddInDesignerObjects, /* wMajor = */ 1, /*
wMinor = */ 0>
{
public:
CConnectProxy()
: m_pConnect(NULL)
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_CONNECTPROXY)
BEGIN_COM_MAP(CConnectProxy)
COM_INTERFACE_ENTRY2(IDispatch, AddInDesignerObjects::IDTExtensibility2)
COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
END_COM_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct();
void FinalRelease();
public:
//IDTExtensibility2 implementation:
STDMETHOD(OnConnection)(IDispatch * Application,
AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch *AddInInst,
SAFEARRAY **custom)
{
HRESULT hr = m_pConnect->OnConnection(Application, ConnectMode,
AddInInst, custom); // no PIA, exception in this
if (FAILED(hr)) {
if (hr == 0x80070002)
DisplayError (hr, L"Could not call OnConnection in managed code.\nError
probably due to Office PIAs not installed.");
else
DisplayError (hr, L"Could not call OnConnection in managed code.");
}
return hr;
}
STDMETHOD(OnDisconnection)(AddInDesignerObjects::ext_DisconnectMode
RemoveMode, SAFEARRAY **custom )
{
HRESULT hr = m_pConnect->OnDisconnection(RemoveMode, custom);
if (FAILED(hr))
DisplayError (hr, L"Could not call OnDisconnection in managed code.");
return hr;
}
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom )
{
HRESULT hr = m_pConnect->OnAddInsUpdate(custom);
if (FAILED(hr))
DisplayError (hr, L"Could not call OnAddInsUpdate in managed code.");
return hr;
}
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom )
{
HRESULT hr = m_pConnect->OnStartupComplete(custom);
if (FAILED(hr))
DisplayError (hr, L"Could not call OnStartupComplete in managed code.");
return hr;
}
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom )
{
HRESULT hr = m_pConnect->OnBeginShutdown(custom);
if (FAILED(hr))
DisplayError (hr, L"Could not call OnBeginShutdown in managed code.");
return hr;
}
protected:
// caches pointer to managed add-in
AddInDesignerObjects::IDTExtensibility2 *m_pConnect;
};
OBJECT_ENTRY_AUTO(__uuidof(ConnectProxy), CConnectProxy)