VB6 COM class with C # update

I have a particularly difficult situation here that I would like to throw a little more feedback there (I am the only .NET developer in the company I work for, so no one can bounce).

I was instructed to replace the aging VB6-compatible ActiveX component, which is consumed by an application that contains both the use of VB6 and the use of the VB.NET component that I am replacing.

I have complete source code for all of these components, so I see usage examples.

For this discussion, the components could be named:

MyVb6.dll
MyApp (with VB.NET and VB6 components)

During the build process for, MyAppthey use the TlbImp tool to then create the interop library:

Interop.MyVb6.dll

Using

In most cases, the use of this happens as expected using a method CreateObject(), for example:

Private Property MyProp() As Object
    Get
        Try
            If m_myProp Is Nothing Then
                m_myProp = CreateObject("MyVb6.MyVb6Obj")
                m_myProp.Initialize()
            End If
        Catch : End Try
        Return m_myProp
    End Get

However, in one case, I found that they seem to have changed tactics on how to consume this interplanetary DLL, and they have a static link to it and a typed property, for example:

Private Property MyProp() As MyVb6.MyVb6ObjClass 'Whilst this is strongly typed, it is from the interop dll ...
    Get
        If m_myProp Is Nothing Then
            m_myProp = CreateObject("MyVb6.MyVb6Obj")
            m_myProp .Initialize()
        End If
        Return m_myProp 
    End Get

The cost of restoring and redeploying the entire application is completely eliminated, so I have no other option but to replace only MyVb6.dll.

What I hope to find here is a practical solution ...

Replacement

What I have done so far is written by the dll replacement skeleton, and since the instances of the object are created using the well-known string value that I added ProgId, for example:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("xxx")]
[ProgId("MyVb6.MyVb6Obj")]
public class MyNewCSharpVersion : IMyNewCSharpVersion
{
    ...
}

, , ..

, , COM . , , ?

, dll VB6, :

Dim myObj As MyVb6.MyVb6Obj

, , , .

- - , .

+4
1

, :

namespace MyVb6 {
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [Guid("xxx")]
    public class MyVb6Obj : _IOldVb6Version
    {
        ...
    }
}

. . VB6, , IOldVb6Version IID, , . , Oleview.exe, File + View Typelib.

+6

Source: https://habr.com/ru/post/1527356/


All Articles