简体   繁体   English

.NET Interop通过VB6表格byRef

[英].NET Interop Passing VB6 Form byRef

I am trying to develop a .NET class that updates a VB6 Form and its controls with various new captions (It is in an assembly that is COM visible). 我正在尝试开发一个.NET类,以使用各种新标题更新VB6表单及其控件(它在COM可见的程序集中)。

I pass a VB6 form ByRef as an object to the .NET class and then update the caption etc on the form as follows: 我将VB6表单ByRef作为对象传递给.NET类,然后按如下所示更新表单上的标题等:

Public Sub AddFormRefLegacy(ByRef objForm As Object)
    Try

        objForm.Caption = "some new caption"

        For Each ctl As Object In objForm.Controls

            Select Case TypeName(ctl)
                Case "Label"
                    ctl.caption = "some new caption"
                Case "Frame"
                    ctl.caption = "some new caption"
                Case "CommandButton", "PushButton"
                    ctl.caption = "some new caption"

                'etc etc

This works about 85% of the time but occasioanlly I get a run time error 80131500 no such interface (E_NOINTERFACE ) 这大约有85%的时间有效,但是有时我遇到运行时错误80131500,没有这样的界面(E_NOINTERFACE

I'm not sure exactly where this is throwing the error but can anyone see anything obviously wrong with this? 我不确定这是在哪里引发错误的,但是有人能看到这明显有问题吗?

EDIT 编辑

The problem seems to be occurring on this section: 该部分似乎发生了问题:

Case "ITabStrip" 'MS Common Controls 6
    For i = 0 To ctl.Tabs.Count - 1 ' this sometimes throws the error!
        ctl.Tabs(i + 1).Caption = FindValue(objForm.Name, ctl.Name, i, ctl.Tabs(i + 1).Caption)
    Next

One possible problem might be that VB6 labels aren't windowed controls but are drawn on the form's window. 一个可能的问题可能是VB6标签不是窗口控件,而是绘制在窗体的窗口上。 Another possible problem is if you're using certain 3rd party controls it's likely that they're using owner draw techniques that might do unexpected things. 另一个可能的问题是,如果您使用某些第三方控件,则很可能他们使用的所有者绘制技术可能会执行意外的操作。

I'd suggest trying to narrow it down by control and see if any of them have the problem. 我建议尝试通过控制缩小范围,看看是否有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM