Excel crash with bad reference

Jul 14, 2012 at 1:33 AM

Hi Keith,

I'm trying to follow up a bug report in Excel-DNA, and was wondering whether you could perhaps check the native equivalent with your library?

The following code, run as a macro from a menu or Alt+F8 causes an access violation immediately in my Excel 2010. When run directly from AutoOpen it doesn't crash immediately, but there is an access violation when Excel closes, so bad things still happen. 

ExcelReference cell = (ExcelReference)Excel(xlfTextref, "R2C3", false);

This issue is the cell reference, which needs a sheet name or at least a ! when called from an .xll. This code works fine:

ExcelReference cell = (ExcelReference)Excel(xlfTextref, "!R2C3", false);

I'm just trying to check whether the crash is an Excel bug where the parameter checking is just poor, or whether my Excel-DNA code might be corrupting something.

Any help would be appreciated.

Thank you,


Jul 14, 2012 at 3:39 PM
Edited Jul 14, 2012 at 3:41 PM

Hi Govert,

Looks like an xlSet bug.

OPER12 cell = Excel<XLOPER12>(xlfTextref, OPER12(L"R2C3"), OPER12(false));
ensure (cell.xltype == xltypeRef);
Excel<XLOPER12>(xlSet, cell, OPER12(123.45)); // access violation


OPER12 cell = Excel<XLOPER12>(xlfTextref, OPER12(L"!R2C3"), OPER12(false));
ensure (cell.xltype == xltypeSRef);
Excel<XLOPER12>(xlSet, cell, OPER12(123.45)); // works fine
Jul 14, 2012 at 5:30 PM
Edited Jul 14, 2012 at 5:31 PM

Thanks for confirming that Keith!

At least now I know it's not a bug in my code.

It's not just xlSet - a variety of other calls can trigger the crash with such a reference. I also find that Excel crashes when the SheetId of a reference is set to some invalid random value. But the example above is worse, since the reference is actually returned by Excel from a valid API call. I'd expect Excel to have enough parameter validation to gracefully fail any call if the SheetId of a reference is not valid.

I'll try to report it via the Excel for Developers forum.