vb6 - 如何在外部 COM 调用期间抑制 "This action cannot be completed"消息?

标签 vb6 com-interop

背景

我正在使用 Visual Basic 开发一个调用进程外 COM 服务器(用 C# 编写的包装 .NET 组件)的应用程序。此组件执行冗长的计算(超过 10 秒),并在计算进行时尝试与 GUI(VB6 端的一部分)交互导致程序发出类似于(并具有以下内容的确切措辞)的消息:

http://www.symantec.com/business/support/library/BUSINESS/ATLAS/images_v1/324876/dlo.jpg

抱歉图片质量很差,我无法在工作之余上传屏幕截图。

问题

有没有办法以编程方式或通过项目或构建配置来抑制此消息?

附录 1

尝试设置 App.OleServerBusyTimeout 会产生运行时错误 369(操作在 ActiveX DLL 中无效)。这是 ActiveX dll 的一部分,我无法改变它。除了在主应用程序中设置该属性,或者将调用减少到小于现有超时之外,是否没有其他解决方案?

最佳答案

如果您想阻止任何消息出现(例如,如果您将光标更改为沙漏),那么您需要使用 App.OleRequestPendingTimeout而不是 App.OleServerBusyTimeout .

您也可以选择使用 App.OLERequestPendingMsgText 设置备用消息.这样做将仅通过一个 OK 按钮向用户显示您的自定义消息,这样就不会那么困惑了。

下面是一些示例代码:

' set up special message if user interacts with application while waiting on the
' long-running operation to complete
' see http://support.microsoft.com/kb/138066

Dim originalOLEPendingMessage As String
originalOLEPendingMessage = App.OleRequestPendingMsgText
App.OleRequestPendingMsgText = "Please be patient while your request is processed."

Dim originalOLEPendingTimeout as Long
originalOLEPendingTimeout = App.OleRequestPendingTimeout
App.OleRequestPendingTimeout = 10000

On Error GoTo Finally
' Call long-running process here

Finally:
' If an actual error occurred we want to capture all the properties of Err
' so we can re-raise it after we clean up
Dim errNumber As Long
Dim ERRSOURCE As String
Dim errDesc As String
Dim errHelpFile As String
Dim errHelpContext As Long

errNumber = Err.Number
ERRSOURCE = Err.Source
errDesc = Err.Description
errHelpFile = Err.HelpFile
errHelpContext = Err.HelpContext

App.OleRequestPendingMsgText = originalOLEPendingMessage
App.OleRequestPendingTimeout = originalOLEPendingTimeout 

If errNumber <> 0 Then
    Err.Raise errNumber, ERRSOURCE, errDesc, errHelpFile, errHelpContext
End If

有关更长的讨论,请参阅 Microsoft 知识库文章 How To Handle OLE Automation Server Timeout and Synchronization .

关于vb6 - 如何在外部 COM 调用期间抑制 "This action cannot be completed"消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12899433/

相关文章:

vb.net - 将 HDD Serial # VB6 代码转换为 VB.NET 代码

c# - 在不了解领域知识的情况下逆向工程 VB6 代码的最佳实践方法

c# - 无法分配给从 VBA 使用的 C# 类中的哈希表项

c# - 无法从 vbscript 调用 c# 代码 - ActiveX 错误

.net - 处理或将错误从 .NET 程序集传递给 COM 客户端/消费者

c# - XSD 模式到 COM 接口(interface)

c#.net COM dll 中断了对 vb6 应用程序的引用

windows - Windows如何决定是否显示UAC提示符?

c# - COM 互操作传递错误的指针,只有一个字节的数据

c# - 未发布 Excel Interop 对象