How to manage the generated COM GUID generated by AutoDual

My problem is that I have a .NET project with COM + -like classes visible to COM. Classes are published to COM using the AutoDual attribute for the class. My problem is that I would like to allow the compiler to automatically generate a COM interface (hence this AutoDual), but I would like to specify a GUID for the generated interface.

The goal is to make small changes, for example:

  • add method
  • changing a method that is not used by a specific client
  • increasing version number of my dll

will not break clients (those who use early binding) and forces them to recompile.

I know (read here: Why shouldn't I use AutoDual? ) That the solution for this would be to create more than 100 interfaces manually and give them a GUID and DispId for each method, so the changes mentioned above will no longer destroy older clients. However, I would like to avoid actually writing these interfaces manually and having to maintain them when new methods need to be added in both the class and the interface.

So far, I have been able to "automatically" publish these classes to COM without writing COM code, using PostSharp to enter the following attributes:

In the classes:

  • ComVisible (true)
  • ClassInterfaceType.AutoDual
  • GUID ("A guide to my own automatically generated but invariant for the gievn FullName class")

About public methods and properties:

  • DispId (xx)// xx dispId, / .

:

  • GUID , .
  • DispId

GUID , , .

, , , GUID, :

  • , , "AutoDualInterfaceGuid (" GUID ")
  • GUID
  • GUID COM-.
  • COM- GUID-.

, GUID COM-, .

+4
1

[Guid] :

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("{7447EEEA-3D48-4D20-80DF-739413718794}")]
public interface IFoo {
    [DispId(42)] void method();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("{40815257-BFD2-43D9-9CF8-FB27CC884C71}")]
[ProgId("Acme.Foo")]
public class Foo : IFoo {
    public void method() { /* etc */ }
}

AssemblyInfo.cs:

[assembly: Guid("B75B31AD-D96A-473F-94E0-37E59847B997")]

DispId , IID , CLSID , ProgId LIBID .

,

ClassInterfaceType.AutoDispatch, , , , . IID, System.Object, mscorlib.tlb, . , . :

GUID ,

, . - COM. , IID . , , , , . , . , IDispatch, , . . . AccessViolationException, , . , , , .

.

+5

All Articles