本文介绍了C ++函数的VB6声明给出了“错误的DLL调用约定”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此C ++函数的正确VB6声明是什么?

What is the correct VB6 declaration for this C++ function?

LPCWSTR* MW_ListReaders(_ULONG Context, int* NumberOfReaders);

以下内容为我提供了错误的DLL调用约定:

The following gave me "Bad DLL calling convention":

Private Declare Function ListReaders Lib "MyDLL.dll" (ByVal Context As Long, _
                                                    ByRef NumberOfReaders As Integer) As Long


推荐答案

在该C ++声明中未指定调用约定。大多数C / C ++编译器默认为 __ cdecl 。如果该函数确实使用 __ cdecl ,则您将无法在VB6中调用它:

There is no calling convention specified in that C++ declaration. Most C/C++ compilers default to __cdecl. If the function does actually use __cdecl then you will not be able to call it in VB6:

注意:在Visual Basic中创建的.EXE文件将允许您调用已用_cdecl调用约定声明的DLL函数,而不会发生错误。只有当您尝试从Visual Basic IDE运行程序时调用此类函数时,Visual Basic才会生成以下错误:

NOTE: An .EXE file created in Visual Basic will allow you to call a DLL function that has been declared with the _cdecl calling convention without an error. It is only when you try to call such a function when running a program from the Visual Basic IDE, that Visual Basic generates the following error:

运行时错误'49 ':
错误的DLL调用约定

Run-time Error '49': Bad DLL Calling Convention

EXE版本允许您调用此类函数的事实已被Microsoft确认为错误。您不应该依赖此行为,因为在Visual Basic的将来版本中这可能会更改。

The fact that the EXE version allows you to call such functions has been confirmed to be a bug by Microsoft. You should not rely on this behavior as this might change in future versions of Visual Basic.

这篇关于C ++函数的VB6声明给出了“错误的DLL调用约定”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 18:16
查看更多