add-in shim - ConnectProxy.h - exception thrown

D

David Thielen

Hi;

Ok, if the PIAs are missing, then an exception is thrown inside the
m_pConnect->OnConnection() call inside ConnectProxy.h. It looks like it is a
kernel exception being thrown.

Does anyone know how to put a try/catch around this as it is a kernel
exception? And how do I pass the exception back up after I call MessageBox?

And is it ok to call MessageBox in the catch handler? And if so, dod I have
to make it a system modal message box?

(I'm afraid it's been years since I've done low-level Windows programming so
I don't remember what all the limitations are in this kind of situation.)
 
P

Peter Huang

Hi

Do you mean the try...catch block can not catch the exception?
What is the exception do you get?
This Shim is a ATL project, I think there is a possibility that the
exception has been handled internally, you may have a check by digging into
the ATL code.

If I have any misunderstanding, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hello;

That is what I am asking - how can I get the exception thrown inside the
OnConnection call. I need to get that to tell the user that the PIAs could
not be located.

Otherwise if there are no PIAs it fails silently and there is no way to tell
the user what went wrong.

thanks - Dave
 
D

David Thielen

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)
 
P

Peter Huang

Hi David,

Thank you for sharing the experience in the community.
Aslo if the exception has been catch in the inner call and did not rethrown
we can not catch the exception outside.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rob Lorimer

David,

You include 2 header files that I don't have:

#include "COMAddInShim.h"
#include "DisplayError.h"

You may have renamed the headers created from the shim wizard?
My headers are as follows, how would they relate to the 2 you include?

CLRLoader.h ... I replaced this with your updated one.
ConnectProxy.h
Resource.h
ShimConfig.h
stdafx.h
 
D

David Thielen

COMAddInShim.h is generated by the MIDL compiler. It's name also comes from
that.

DisplayError.h is a file I created for displaying error messages in the
shim. One of these days I plan to clean up my shim code (AutoTag is
hard-coded in it) and post it. But I need to do some work on it first because
otherwise I'll get a ton of questions on it.

thanks - dave
 

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