XL97: "Bad DLL Calling Convention" When Running a Macro

Last reviewed: February 27, 1998
Article ID: Q158905
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

When you run a Visual Basic for Applications macro in Microsoft Excel 97, you may receive the following error message:

   Run-time error '49':
   Bad DLL calling convention

CAUSE

This problem may occur when all of the following conditions are true:

  • The Visual Basic macro code contains one or more Declare Function statements.

        -and-
    
  • One of the Declare Function statements refers to a function in a dynamic-link library file (DLL) that uses the _cdecl calling convention.

        -and-
    
  • Within the code, you make a call to the declared function.

In Microsoft Excel 97, Visual Basic macros can only call functions that use the _stdcall calling convention. Functions that use the _cdecl calling convention are not supported.

MORE INFORMATION

DLLs in Microsoft Windows support two main calling conventions: _cdecl and _stdcall. Most 32-bit DLLs that are included with Microsoft Windows 95 and Microsoft Windows NT support the _stdcall calling convention; the _cdecl calling convention is generally used by older DLLs.

If a DLL supports only the _cdecl calling convention, you cannot call functions in that DLL from a Visual Basic macro in Microsoft Excel 97. For example, if your code includes the following function declaration:

   Declare Function memcpy& Lib "Crtdll" (ByRef Dest&, ByVal Src&, _
       ByVal Count&)

and then attempts to call the memcpy& function, you will receive the error message described in this article. This behavior occurs because macros in Microsoft Excel 97 cannot call functions that use the _cdecl calling convention.

NOTE: In earlier versions of Microsoft Excel, you can make calls to functions that use the _cdecl calling convention.


Additional query words: XL97
Keywords : kberrmsg xlvbainfo xl97vbmigrate
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.