XL97: "Unhandled Exception in Mso97.dll" When Using XlCoerce

ID: Q166287


The information in this article applies to:
  • Microsoft Excel Software Development Kit, version 5.0
  • Microsoft Excel 97 for Windows


SYMPTOMS

When you use XlCoerce in a dynamic-link library (DLL) that is loaded by Microsoft Excel 97, the following error message appears

Unhandled exception in excel.exe (MSO97.DLL): 0xc0000005: Access Violation
and Microsoft Excel stops responding.


CAUSE

This problem occurs when the following conditions are true:

  • You are using Microsoft Excel 97.


  • -and-

  • The DLL function is called from a worksheet as a result of a calculation.


  • -and-

  • You are attempting to use XlCoerce to coerce a reference XLOPER that refers to a range that contains text.



WORKAROUNDS

To correct this problem, install Microsoft Excel 97 Service Release 1 (SR- 1).

To work around this problem, use one of the following methods.

Method 1

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
If XLOPER does not reference any cells that contain text, use the following function to determine whether to use XlCoerce:

        /*********
      *  RangeContainsText
      *
      *  Purpose: Determine if a XLOPER reference points to a range that
      *           contains any cells containing text.  Microsoft Excel 97
      *           stops responding if XlCoerce is used to convert a
      *           reference to a string.
      *
      *  Parameter:
      *           pxRange[in]    Range to check.
      *
      *  Return:  TRUE  -  Range contains text, or Excel4 call fails.
      *           FALSE -  Range does not contain text and it is safe to
      *                    use XlCoerce on the reference as a workaround
      *                    to the problem.
      *
      *******************************************************************/ 
      BOOL RangeContainsText(LPXLOPER pxRange)
      {
         DWORD dwRet = 0;
         XLOPER xIsText;
         BOOL bRet = TRUE;  // Value returned if Excel4 Fails

         // Check determine whether you are working with a range
         if( !((xltypeSRef | xltypeRef) & (pxRange->xltype)))
            return bRet;

         dwRet = Excel4(xlfIstext,&xIsText,1,pxRange);
         if( xlretSuccess == dwRet && xltypeErr != xIsText.xltype)
         {
            XLOPER xRet;
            dwRet = Excel4(xlfOr,&xRet,1,&xIsText);
            if( xlretSuccess == dwRet && xltypeBool == xRet.xltype)
               bRet = xRet.val.bool;
         }
         Excel4(xlFree,0,1,&xIsText);
         return bRet;
      } 

Method 2

Instead of using the R data type to pass a range or a cell that may contain text, use the OPER data type (P). This data type does not support references, but it does support arrays, numbers, Boolean values, and errors. For more information about the Register function, see the Microsoft

Excel Software Development Kit (SDK).

Method 3

When the cells contain text, use Automation to get the values from the cells. You can use the information in a reference XLOPER to build a Range object that you can pass to Microsoft Excel through Automation. When you do this, values in cells are returned to the DLL as a SAFEARRAY, which you can use to build an XLOPER array of values.

The 32-bit Generic Framework example for Microsoft Excel in the Microsoft Software Library implements this method. The method is integrated in the Microsoft Excel SDK framework; therefore, it's not necessary to change any code that uses the Excel() wrapper.

For additional information, please see the following article in the Microsoft Knowledge Base:
Q152152 SAMPLE: FRMWRK32.EXE: Updated Generic.xll Template for Excel
To integrate the framework into another project, use the following steps:

  1. Add xlAuto.cpp, xlCoerce.cpp and Framewrk.c to the existing project and place framewrk.h and xlcoerce.h in the directory for the project.


  2. Call InitFramework() from the xlAutoOpen.


  3. Call QuitFramework() from the xlAutoClose.


  4. Add "CheckInstance" to the exports section of the DEF file for the project.



STATUS

Microsoft has confirmed this to be a problem in Microsoft Excel 97 for Windows. This problem was corrected in Microsoft Excel 97 SR-1.

For additional information about SR-1, please see the following article in the Microsoft Knowledge Base:

Q172475 OFF97: How to Obtain and Install MS Office 97 SR-1

Additional query words: sr1 crash 97 xldk xlsdk Excel4 Excel

Keywords : kberrmsg kbprg kbdta kbdtacode KbVBA
Version : :5.0; WINDOWS:97
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.