开发者

.NET Interop Passing VB6 Form byRef

开发者 https://www.devze.com 2023-04-12 18:41 出处:网络
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).

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).

I pass a VB6 form ByRef as an object to the .NET class开发者_StackOverflow and then update the caption etc on the form as follows:

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)

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. 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.

0

精彩评论

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

关注公众号