【问题标题】:VB Crashes with no indicationVB 崩溃,没有任何迹象
【发布时间】:2014-08-02 14:35:45
【问题描述】:

如下面的代码,我声明了一个dll来使用它的函数,成功时返回0,否则返回0。

我需要函数生成的宽度、高度、步幅、长度、字节数,所以我使用 ByRef 来声明它们。当我启动它时它运行良好,但在它显示 3 msgbox 后,Visual Basic 崩溃。

我2天前刚开始vb,我知道这一定是一个菜鸟问题,但我什至不知道问题是什么,所以......帮帮我。

有什么让你们困惑的地方请告诉我,我会马上改正的。

这是 DLL 的纪录片

sn 字符

宽度 int (IN/OUT)

高度 Int (IN/OUT)

字节 char* (IN/OUT)

跨步(进/出)

len int(输入/输出)

Private Declare Function Ict_WMK_ISV Lib "C:\acd.dll" (ByVal PrinterModel As String, ByRef width As Long, ByRef height As Long, ByRef bytes As Variant, ByRef stride As Long, ByRef leng As Long) As Integer

Private Sub Command1_Click()

'Ict_WMK_ISV (Fax)

Dim width As Long
Dim height As Long
Dim stride As Long
Dim leng As Long
Dim bytes As Variant
Dim printmodel As String

Dim iResult As Integer

printmodel = "Samsung SCX-6x45 Series PCL6"

If IsNull(bytes) Then
  MsgBox ("null")
Else
  MsgBox ("not null")
End If

bytes = Empty


iResult = Ict_WMK_ISV(printmodel, width, height, bytes, stride, leng)


MsgBox (Str(iResult))

End Sub

【问题讨论】:

  • 对于代码 'bytes = Empty' 是 'Empty' 在别处声明的变量。我在这里看不到它是一个 VB 关键字。 msdn.microsoft.com/en-gb/library/dd409611.aspx
  • 您是否收到任何错误消息?
  • 尝试添加一个简单的错误处理程序(参见here - 只需添加on error goto、标签和Msgbox(err.message)
  • bytes 不太可能是 Variant,更常见的是返回类型是 Long 而不是 Integer。但是如果没有关于函数Ict_WMK_ISV的文档,那么这些都是猜测。 dll 是否带有文档或头文件?
  • 我们还有err.lastdllerror。请注意,您必须On Error Resume Next 才能使用它。 LastDLLError 属性仅适用于从 Visual Basic 代码进行的 DLL 调用。当进行这样的调用时,被调用的函数通常会返回一个指示成功或失败的代码,并填充 LastDLLError 属性。检查 DLL 函数的文档以确定指示成功或失败的返回值。每当返回失败代码时,Visual Basic 应用程序应立即检查 LastDLLError 属性。有关详细信息,请参阅 API 调用 SetLastError。

标签: visual-studio vba vb6 basic


【解决方案1】:

然后在windbg下运行(下载安装Windows调试工具)

http://msdn.microsoft.com/en-us/windows/hardware/hh852363

安装 Windows SDK,但只需选择调试工具。

在 C:\ 中创建一个名为 Symbols 的文件夹

启动 Windbg。文件菜单-符号文件路径并输入

srv*C:\symbols*http://msdl.microsoft.com/download/symbols

来自http://blogs.msdn.com/b/arvindsh/archive/2006/08/30/731150.aspx

How to generate symbol files for Visual Basic 6.0

In VB6, symbols are not created by default. To create symbols for your VB6 applications, follow these steps:

•Open the source code for your project.

•Select "<projectname> Properties" from the Project menu.

•In the Compile tab, check Create Symbolic Debug Info and select No Optimizations

•Recompile. This will create a .PDB file (the symbols) in the same directory as your .DLL / .EXE / .OCX file.

•Note: This does *not* break binary compatibility.

(如果你设置了环境变量link=/pdb:none符号存储在编译文件中)

当它崩溃时,您可以获得异常信息。

【讨论】:

    猜你喜欢
    • 2016-02-22
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多