// The call to LPenHelper will cause an AccessViolation after Excel starts shutting down.
        // .NET40: If this library is recompiled to target .NET 4+, we need to add an attribute to indicate that this exception 
        // (which might indicate corrupted state) should be handled in our code.
        // For now, we target .NET 2.0, and even when running under .NET 4.0 we'll see the exception and be able to handle is.
        // See: http://msdn.microsoft.com/en-us/magazine/dd419661.aspx
        // (Also for CheckExcelApiAvailable())

        // [HandleProcessCorruptedStateExceptions]
        static int CallPenHelper(int wCode, ref XlCall.FmlaInfo fmlaInfo)
        {
            try
            {
                // (If Excel is shutting down, we see an Access Violation here, reading at 0x00000018.)
                return XlCall.LPenHelper(XlCall.xlGetFmlaInfo, ref fmlaInfo);
            }
            catch (AccessViolationException ave)
            {
                throw new InvalidOperationException("LPenHelper call failed. Excel is shutting down.", ave);
            }
        }
Exemplo n.º 2
0
 public XlCallException(XlCall.XlReturn xlReturn)
 {
     this.xlReturn = xlReturn;
 }