Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your IDL isn't valid, an interface that is attributed with [oleautomation] should derive from IDispatch, not IUnknown. I'll give the proper declarations and hint where you need to modify them to get yours.</p> <p>You cannot declare indexed properties in C#, the C# team refuses to implement them. Version 4 has support for indexed properties that are declared in a COM type library but still doesn't allow declaring them yourself. The workaround is to use the VB.NET language, it has no qualms about it. Add a VB.NET class library project to your solution. Make it look similar to this:</p> <pre><code>Imports System.Runtime.InteropServices Namespace Mumble &lt;ComVisible(True)&gt; _ &lt;Guid("2352FDD4-F7C9-443a-BC3F-3EE230EF6C1B")&gt; _ &lt;InterfaceType(ComInterfaceType.InterfaceIsDual)&gt; _ Public Interface IExample &lt;DispId(0)&gt; _ Property Indexer(ByVal index As Integer) As Integer &lt;DispId(1)&gt; _ Property SomeProperty(ByVal index As Integer) As String End Interface End Namespace </code></pre> <p>Note the use of <code>&lt;DispId&gt;</code>, dispid 0 is special, it is the default property of an interface. This corresponds to the indexer in the C# language.</p> <p>All you need VB.NET for is the declaration, you can still write the <em>implementation</em> of the interface in the C# language. Project + Add Reference, Projects tab and select the VB.NET project. Make it look similar to this:</p> <pre><code>using System; using System.Runtime.InteropServices; namespace Mumble { [ComVisible(true)] [Guid("8B72CE6C-511F-456e-B71B-ED3B3A09A03C")] [ClassInterface(ClassInterfaceType.None)] public class Implementation : ClassLibrary2.Mumble.IExample { public int get_Indexer(int index) { return index; } public void set_Indexer(int index, int Value) { } public string get_SomeProperty(int index) { return index.ToString(); } public void set_SomeProperty(int index, string Value) { } } } </code></pre> <p>You need to run Tlbexp.exe on <em>both</em> the VB.NET and the C# assembly to generate the type libraries. The C# one with the implementation includes the VB.NET one.</p> <p>To get the interface to derive from IUnknown instead of IDispatch, edit the interface declaration. Remove the DispId attributes and use ComInterfaceType.InterfaceIsUnknown</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload