呼吁.NET 3.5大会第一次通话后,VB6自动化错误错误、大会、NET

2023-09-07 01:03:13 作者:Timeless。白夜

有些我已经检查了来源: http://www.experts-exchange.com/Programming/Languages/.NET/Visual%5FBasic.NET/Q%5F23359339.html 的http://mygreenpaste.blogspot.com/2006/03/net-framework-20-configuration-tool.html http://support.microsoft.com/kb/186063

Some of the sources I've checked already: http://www.experts-exchange.com/Programming/Languages/.NET/Visual%5FBasic.NET/Q%5F23359339.html http://mygreenpaste.blogspot.com/2006/03/net-framework-20-configuration-tool.html http://support.microsoft.com/kb/186063

我正忙着开发.NET模块,将钩到我们现有的VB6 code。我创建从中推出新的code,它包括一个按钮形式的测试VB6的项目,并在按钮的点击事件是

I'm busy developing .NET modules that will hook into our existing VB6 code. I've created a test VB6 project from which to launch the new code which comprises of a form with a button, and on the button's click event is

Dim launcher As New VB6InteropLaunchPad.launcher
launcher.FormTypeEnum = FormTypeEnum_MySpecificForm
launcher.launchAppropriateForm

这是成功的,我第一次点击的按钮。不过,如果我再次点击该按钮,出现以下错误:

It is successful the first time I click the button. However, if I click the button again, I get the following error:

Run-time error '-2146233079 (80131509)': Automation Error

后续调用.NET code失败,并出现相同的错误消息,除非我关闭并重新启动IDE。如果我编译VB6的项目,以一个EXE同样的事情发生。我不得不关闭该exe文件,并再次运行它能够访问.NET code。

Subsequent calls to the .NET code fail with the same error message unless I close and restart the IDE. If I compile the VB6 project to an EXE the same thing happens. I have to close the EXE and run it again to be able to access the .NET code.

我试过在 http://support.microsoft.com/kb/186063,也做了以下内容:     显式的选项

I've tried the suggestion on http://support.microsoft.com/kb/186063 and did the following: Option Explicit

' http://support.microsoft.com/kb/186063

Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Private Declare Function FormatMessage Lib "kernel32" Alias _
    "FormatMessageA" (ByVal dwFlags As Long, lpSource As Long, _
    ByVal dwMessageId As Long, ByVal dwLanguageId As Long, _
    ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Any) _
    As Long

Private Function MessageText(lCode As Long) As String
     Dim sRtrnCode As String
     Dim lRet As Long

     sRtrnCode = Space$(256)
     lRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0&, lCode, 0&, _
                  sRtrnCode, 256&, 0&)
     If lRet > 0 Then
         MessageText = Left(sRtrnCode, lRet)
     Else
         MessageText = "Error not found."
     End If
End Function

On Error GoTo errHandler
   Dim launcher As New VB6InteropLaunchPad.launcher
   launcher.FormTypeEnum = FormTypeEnum_MySpecificForm
   launcher.launchAppropriateForm
   Exit Sub

errHandler:
   MsgBox MessageText(Err.Number)
   MsgBox Err

但没有发现错误。

but the error was not found.

在如何解决这一问题的任何想法?我试图设置发射器=无,但它并不能帮助。

Any ideas on how to fix this? I tried to set launcher = Nothing but it doesn't help.

谢谢你们。

推荐答案

鉴于这一切在这里所涉及的,我不认为有足够的信息来做出有意义的猜测,实际的问题。如果我是你的情况,我可能会做是为了调试在Visual Studio中的.NET组件的第一件事就是查看问题是否是一个未处理的异常从.NET组件来了:

Given all that is involved here, I don't think there is enough information to make a meaningful guess as to the actual issue. If I were in your situation, the first thing I would probably do is debug the .NET component in Visual Studio in order to see if the problem is an unhandled exception coming from the .NET component:

(可选,但往往有帮助)配置VB6项目在编译期间生成一个PDB文件。打开VB6项目并转到项目 - > MyProject的属性...菜单项。选择编译选项卡,并选中创建符号调试信息 编译VB6的项目(文件 - >请MyProject.exe)。 打开.NET组件项目/解决方案,到项目 - > MyDotNetProject属性...菜单项。选择调试选项卡。设置开始行动,以启动外部程序,并浏览到经步骤2中生成.exe文件。 (可选,但往往有帮助)选中启用非托管code调试。 在调试!

希望你会尝试你列出相同的情况下,这时候就会导致异常,反过来,会导致VS调试器打破了.NET code中的违规行。如果您看不到任何行为上的变化,它可能有助于去调试 - >例外...菜单项(VS),并检查相应的复选框,立即打破,当一个公共语言运行库异常是抛出。

Hopefully you'll try the same scenario you outlined and this time it will cause an exception that, in turn, causes the VS debugger to break on the offending line of .NET code. If you don't see any change in behavior, it may be helpful to go to the Debug -> Exceptions... menu item (in VS) and check the appropriate check box to break immediately when a "Common Language Runtime Exception" is thrown.