vba 调试错误的 DLL 调用约定错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/574587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:14:43  来源:igfitidea点击:

Debug a bad DLL calling convention error

vbams-accessdllaccess-vba

提问by Malcolm

How do I debug a bad DLL calling convention error in MSAccess VBA code?

如何在 MSAccess VBA 代码中调试错误的 DLL 调用约定错误?

I made some changes to a function in a module and then got the error. How do a debug it to find the cause?

我对模块中的函数进行了一些更改,然后出现错误。如何调试它以找到原因?

The error occurs on the Exit function statement of the function.

该错误发生在该函数的 Exit 函数语句上。

回答by Jon Artus

I've seen this in Excel before without any external references. It happened, as with your problem, on an Exit Function call. Excel doesn't seem to have a /decompile option, but I fixed it by making a change in one of my class modules, executing a compilation from the Debug menu, and then undoing the change. I suspect that one of my class modules had mis-compiled for some reason, and Excel won't re-compile unless it thinks something has changed.

我之前在 Excel 中看到过这个,没有任何外部引用。与您的问题一样,它发生在 Exit Function 调用上。Excel 似乎没有 /decompile 选项,但我通过在我的一个类模块中进行更改、从“调试”菜单执行编译,然后撤消更改来修复它。我怀疑我的一个类模块由于某种原因编译错误,Excel 不会重新编译,除非它认为某些事情发生了变化。

回答by Fionnuala

Have you checked your references and decompiled?

你检查过你的参考资料并反编译了吗?

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" 
                                "d:\My Documents\access\mayapp.mdb" /decompile

See also:
http://www.granite.ab.ca/access/decompile.htm
VBScript Decompile

另见:
http: //www.granite.ab.ca/access/decompile.htm
VBScript 反编译



Check references in code

检查代码中的引用

Dim ref As Reference
Dim sMsg As String

''Available since 2010
If BrokenReference Then
    For Each ref In References
        ''Available since at least 2000
        If ref.IsBroken Then
            sMsg = sMsg & "Ref Name: " & ref.Name
            'Also, if required
            'sMsg = sMsg & vbCrLf & "Built In: " & ref.BuiltIn
            'sMsg = sMsg & vbCrLf & "Full Path: " & ref.FullPath
            'sMsg = sMsg & vbCrLf & "GUID: " & ref.Guid
            'sMsg = sMsg & vbCrLf & "Kind: " & ref.Kind
            'sMsg = sMsg & vbCrLf & "Major (version number): " & ref.Major
            'sMsg = sMsg & vbCrLf & "Minor (version number): " & ref.Minor
            sMsg = sMsg & vbCrLf & "=================================" & vbCrLf
        End If
    Next
    MsgBox sMsg
End If

回答by AronVanAmmers

I experienced and worked around this error using the .NET library for WinSCPfrom MS Access VBA.

我使用MS Access VBA 中的WinSCP .NET 库解决并解决了此错误。

What happened was:

发生的事情是:

  1. A function UploadSomethingfor connecting to an SFTP server and uploading a file worked fine.
  2. Within the function UploadSomethingchanged the "resume support" option with this code: myTransferOptions.ResumeSupport.State = TransferResumeSupportState.TransferResumeSupportState_Off
  1. 函数UploadSomething用于连接到SFTP服务器上传文件的罚款。
  2. 在函数中UploadSomething使用以下代码更改了“恢复支持”选项:myTransferOptions.ResumeSupport.State = TransferResumeSupportState.TransferResumeSupportState_Off

After the change, the code worked as desired. However in the code that calledUploadSomething, Error 49 was thrown after the function had finished.

更改后,代码按预期工作。但是在调用的代码中UploadSomething,函数完成后抛出了错误 49。

The error happened both when stepping through the code using the debugger and when executing at once outside of the debugger. Recompiling the project didn't work for me.

在使用调试器单步执行代码时和在调试器外立即执行时都会发生错误。重新编译该项目对我不起作用。

What did work was this:

什么工作是这样的:

  1. Remove the reference to the COM component
  2. Add the reference to the COM component
  3. Recompile
  1. 删除对 COM 组件的引用
  2. 添加对 COM 组件的引用
  3. 重新编译

回答by pstraton

In Excel VBA, this can be caused by any of several problems:

在 Excel VBA 中,这可能是由以下几个问题中的任何一个引起的:

  1. A parameter or return-value type mismatch.
  2. An object method (such as AutoFit) applied to an erroneous object variation for which that method isn't available.
  3. A call to an external library function.
  4. Broken library references
  1. 参数或返回值类型不匹配。
  2. 一种对象方法(例如 AutoFit)应用于该方法不可用的错误对象变体。
  3. 调用外部库函数。
  4. 损坏的库引用

For resolutions to these causes, see my post at: Runtime Error 49, Bad DLL calling convention

有关这些原因的解决方案,请参阅我的帖子:运行时错误 49,错误的 DLL 调用约定

回答by RexBarker

We've run into some problems with VBA when trying to call a DLL compiled in Intel Fortran. It turns out that you need to align the calling conventions back to a "C" context with the compiler flag calling convention: cfv

在尝试调用在 Intel Fortran 中编译的 DLL 时,我们遇到了一些 VBA 问题。事实证明,您需要将调用约定与编译器标志调用约定重新对齐到“C”上下文:cfv

More info here on the Intel websiteAnother useful thread on the same problem: Intel Fortran DLL <-> C

英特尔网站上的更多信息关于 同一问题的另一个有用的线程:英特尔 Fortran DLL <-> C

回答by graham.reeds

I've just got this in Excel and wondered if anyone else have gotten it previously. My solution was to move around the references to my own DLL and click 'Compile <Project>'.

我刚刚在 Excel 中得到了这个,想知道是否有其他人以前得到过它。我的解决方案是移动对我自己的 DLL 的引用,然后单击“编译 <项目>”。