vb6 - 在 VB6 应用程序中出现缺少组件错误

标签 vb6 error-handling

我有一个包含大量 3rd 方组件的 VB6 应用程序。该应用程序运行良好,但在退出时(并且仅在作为独立 EXE 运行时,例如不在 IDE 中),它会弹出一条错误消息:

enter image description here

我以前见过这样的错误,但通常它会说明哪个组件缺少依赖项或未正确注册。

我通过 Process Monitor 运行它并获得了以下无法找到的文件:

enter image description here

然后它就退出了。我用谷歌搜索了它找不到的文件名,似乎找不到任何东西。它似乎在寻找 MSComENU、MSComEN 和 MSCOENU dll 的变体。

我检查并重新检查以确保所有第 3 方组件都存在并且它们存在 - 应用程序功能正常,如果它们不存在则不会。

值得注意的是,在 VB6 代码的最后一行(在 Form_Unload 事件中)触发后会发生错误。我知道这一点,因为最后一行是确实出现的消息框。

很久很久以后 编辑 : 我终于重新开始处理这个问题,并通过消除过程解决了这个问题(这是一个漫长的过程)。最后,它与任何 MSCOMM*.dll 条目无关。事实上,我不知道为什么它们仍然出现在 Process Monitor 中。问题要简单得多。

我在主窗体上有几个第 3 方控件。为了不让大量事件处理代码污染主窗体,我将这些控件委托(delegate)给一个新类,如下所示:

' declaration code in main form'
Private WithEvents moDelegateObject as clsDelegateObject

' still in the main form, after initialization'
Set moDelegateObject = new clsDelegateObject
With moDelegateObject
    Set .ThirdPartyCtlHandler1 = me.ThirdPartyCtl1
    Set .ThirdPartyCtlHandler2 = me.ThirdPartyCtl2
    Set .ThirdPartyCtlHandler3 = me.ThirdPartyCtl3
end with

' declarations and properties inside of clsDelegateObject'
Private WithEvents moThirdPartyCtlHandler1 as ThirdPartyCtl
Private WithEvents moThirdPartyCtlHandler2 as ThirdPartyCtl
Private WithEvents moThirdPartyCtlHandler3 as ThirdPartyCtl
Public Event FooEvent() ' other various events as well '

Public Property Set ThirdPartyCtlHandler1(o as ThirdPartyCtl) 
    moThirdPartyCtlHandler1 = o
End Property 
Public Property Get ThirdPartyCtlHandler1() as ThirdPartyCtl
    ThirdPartyCtlHandler1 = moThirdPartyCtlHandler1 
End Property
' ... Repeat for each handler ...'

缺少的是在关闭之前显式释放这些对象的代码。这是 Visual Basic 通常会做的事情。所以我在主窗体的 Form_QueryClose 中添加了以下内容:
With moDelegateObject
    Set .ThirdPartyCtlHandler1 = Nothing
    Set .ThirdPartyCtlHandler2 = Nothing
    Set .ThirdPartyCtlHandler3 = Nothing
End with
Set moDelegateObject = Nothing  

最后一行原来是多余的,但为了完整起见,我把它扔在那里。我认为这是将控件委派给委托(delegate)类并以 Main 形式从它接收事件以及使用大量真正晦涩难懂的 3rd 方控件的组合,这些控件导致了这个问题。第 3 方控件很可能没有干净地释放自己。总之,吸取教训了。

最佳答案

这可能是 DLL_PROCESS_DETACH 或 CoUninitialize 问题。 Raymond Chen 的博客“The Old New Thing”有几篇相关文章:

  • When DLL_PROCESS_DETACH tells you that the process is exiting, your best bet is just to return without doing anything
  • Do you know when your destructors run? Part 1.
  • Quick overview of how processes exit on Windows XP
  • How you might be loading a DLL during DLL_PROCESS_DETACH without even realizing it
  • The thread that gets the DLL_PROCESS_DETACH notification is not necessarily the one that got the DLL_PROCESS_ATTACH notification

  • 正如你所说,这些是第 3 方组件。您可以尝试制作更小的测试用例,直到问题消失以查明有问题的组件。您还可以尝试使用 native 代码调试器并分析生成错误消息的代码。

    最简单的解决方案但是,要解决此问题,请尝试强制所有这些组件的特定加载顺序。在 Main() 或启动表单中,尝试以固定顺序使用每个 3rd 方组件的某些功能。如果错误仍然出现,请更改顺序,直到问题消失。那可能行得通。

    关于vb6 - 在 VB6 应用程序中出现缺少组件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9138558/

    相关文章:

    c++ - 如何创建 COM DLL(类库)?

    com - ActiveX/COM/VB6企业项目的生成过程

    c# - COM 与 VB6 和 C# 互操作

    php - 尝试访问非对象(未分配)的属性时没有错误或警告

    php - set_exception_handler()期望参数(exception_handler)是有效的回调

    c - 与用户创建的结构不兼容的类型

    windows - 如何增加 Windows 10 的最大 GDI 对象数量?

    c - VB6 - 如何通过 .tlb 文件将字符串传递给用 C 编写的 DLL

    php - 如何在 PHP 中记录未捕获的异常?

    c# - 空捕获 block