Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q213554

↑ Back to the top


Symptoms

When you run a Visual Basic for Applications macro in Microsoft Excel, you may receive the following error message:
Run-time error '49':
Bad DLL calling convention

↑ Back to the top


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 2000, Visual Basic macros can only call functions that use the _stdcall calling convention. Functions that use the _cdecl calling convention are not supported.

↑ Back to the top


More information

DLLs in Microsoft Windows support two main calling conventions: _cdecl and _stdcall. Most 32-bit DLLs that are included with Microsoft Windows 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. 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 2000 cannot call functions that use the _cdecl calling convention.

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

↑ Back to the top


Keywords: KB213554, kbprb, kberrmsg

↑ Back to the top

Article Info
Article ID : 213554
Revision : 5
Created on : 10/10/2006
Published on : 10/10/2006
Exists online : False
Views : 237