开发者

Catch an exception/error from an OCX hosted in a .NET Windows Form

I have a .NET Windows Form that I use to host an older VB6 OCX form. That’s something I can’t run from! At least for now...

I’m not sure if this paragraph will be useful, but just in case I will share this information. In order to load this control, my .NET application provides a configuration file that will contain the information about the OCX control. I will then load the control using reflection, create an instance with Activator.CreateInstance and cast this object to a System.Windows.Forms.Control. Then, I add it my .NET form’s Controls collection. This approach works for me.

So, what I want is to catch the OCX exceptions and errors in my .NET Form, or to have any way of开发者_StackOverflow中文版 knowing that this OCX form crashed. Is this possible? Did anyone have a similar experience? By the way, I’m using .NET 2.0.

Thanks.


Since no-one more knowledgeable has answered yet...

  • If you are calling direct from your .Net code into a method/property in the VB6, errors raised in the VB6 should propagate back into the .Net as exceptions.
  • The VB6 code will presumably include event handlers for your form and controls. You need error handlers in those routines, using On Error Goto. I think unhandled errors will crash the application (there's no .Net code in the call stack beneath the Windows events). If you want to communicate the errors back to .Net, you will need to invent a mechanism to do so. Raise a custom event from the VB6 component, or provide a callback from the VB6 into the .Net.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜