Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call TlbExp to make a type library that is embedded in the .xll #472

Merged
merged 4 commits into from
Jun 26, 2022

Conversation

Sergey-Vlasov
Copy link
Contributor

For .NET 6, dscom need to be installed on the development machine:
https://github.com/dspace-group/dscom

And for .NET 6, a COM interface should be explicitly declared, not using ClassInterfaceType.AutoDual.

@Sergey-Vlasov Sergey-Vlasov requested a review from govert June 24, 2022 16:26
@govert
Copy link
Member

govert commented Jun 24, 2022

And for .NET 6, a COM interface should be explicitly declared, not using ClassInterfaceType.AutoDual.
Do you think AutoDispatch still works?

@Sergey-Vlasov
Copy link
Contributor Author

Do you think AutoDispatch still works?

How can I test for it?

For development, I tested with NET6DnaComServer project and NET6Book.xlsm.

The book includes a function call and two macros:

    Sub TestLateBound()
        Dim dnaComServer As Object
        Dim hello As String
        Dim result As Double
    
        Set dnaComServer = CreateObject("DnaComServer.ComLibrary")
        hello = dnaComServer.ComLibraryHello()
        result = dnaComServer.Add(1, 2)
    
        Debug.Print hello, result
    End Sub
    
    Sub TestEarlyBound()
        Dim dnaComServer As NET6DnaComServer.ComLibrary
        Dim hello As String
        Dim result As Double
    
        Set dnaComServer = New NET6DnaComServer.ComLibrary
        hello = dnaComServer.ComLibraryHello()
        result = dnaComServer.Add(1, 2)
    
        Debug.Print hello, result, "E"
    End Sub

The function and both macros worked.

@govert
Copy link
Member

govert commented Jun 24, 2022

Yes I think that code can only work if the IDispatch interface is implemented.
I think it will fail if you put ClassItnerfaceType.None.

I also think that AutoDual still works the same way under .NET 6 as under Framework - it's just that the dscom tool chose not to support it (which I think is fine, for the problematic reasons they point to.)

@Sergey-Vlasov
Copy link
Contributor Author

I also think that AutoDual still works the same way under .NET 6 as under Framework - it's just that the dscom tool chose not to support it (which I think is fine, for the problematic reasons they point to.)

It is not only dscom. In .NET 6 build, I got
warning CS0618: 'ClassInterfaceType.AutoDual' is obsolete: 'Support for IDispatch may be unavailable in future releases.'

And there is CA1408: Do not use AutoDual ClassInterfaceType
https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1408?view=vs-2022&tabs=csharp

@Sergey-Vlasov
Copy link
Contributor Author

Yes I think that code can only work if the IDispatch interface is implemented. I think it will fail if you put ClassItnerfaceType.None.

In NET6DnaComServer/AddIn.cs:

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class ComLibrary : IComLibraryInterface

@govert
Copy link
Member

govert commented Jun 24, 2022

I'm actually super confused. See my answer here: https://groups.google.com/g/exceldna/c/onRDZLJwoBY
I had discovered the issue when making the CTP work under .NET 6. This was the crucial information: dotnet/winforms#4370 (comment)
For the UserControl (the context in both the CTP and the WinForms issue above) it does not work to mark the derived class as AutoDispatch. You have to implement an interface and mark it as the ComDefaultInterface. Apparently this is needed for the IDispatch to be created. The way I'm reading it, the IDispatch is no longer made using reflection (so is made at compile time in the interface case, so still works?) But then what about your example above? Perhaps something to do with the base class. The UserControl class is no longer marked as ComVisible in .NET 5/6. So having a base class that is not ComVisible (so was not compiled knowing that it would need to support IDispatch might break the AutoDispatch by requiring the reflection-based implementation which is no longer supported.

Anyway, it's worth taking note of these quirks, especially about the CTP controls. I forgot about the problem and fix I found in February, just that I had tried it under .NET 6 and did get it to work.

@govert
Copy link
Member

govert commented Jun 24, 2022

I think your example:

    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class ComLibrary : IComLibraryInterface

work because of the interface, where the default is then to generate an IDispatch.

@govert govert merged commit e596cfb into master Jun 26, 2022
@Sergey-Vlasov Sergey-Vlasov deleted the TlbExp branch June 27, 2022 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants