0

I'm trying to implement a Component Object Model interface in C# but I'm running into some issues.

This is the interface

interface IInsModule: IDispatch
{
    [id(0x00000001)]
    HRESULT _stdcall Mod_Initialize(
        [in] IInsDriver *driver,
        [in] IInsCommBase *comm,
        [in] IInsBaseModule *basemod,
        [in] IInsBaseMessage *basemsg,
        [in] IInsLogWriter *logger );

    [id(0x00000002)]
    HRESULT _stdcall Mod_Activate( void );

    [id(0x00000003)]
    HRESULT _stdcall Mod_Finish( void );

    [id(0x00000004)]
    [propput] HRESULT _stdcall Mod_Value( long key, [in] BSTR value );
    [id(0x00000004)]
    [propget] HRESULT _stdcall Mod_Value( long key, [out, retval] BSTR *value );
};

And this is my code so far which has been auto implemented by Visual Studio.

public class CSharpDriver : IInsModule
    {
        public void Mod_Initialize(CoDriver driver, IInsCommBase comm, IInsBaseModule basemod, IInsBaseMessage basemsg, IInsLogWriter logger)
        {
            throw new NotImplementedException();
        }

        public void Mod_Activate()
        {
            throw new NotImplementedException();
        }

        public void Mod_Finish()
        {
            throw new NotImplementedException();
        }

        public string Mod_Value { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
    }

The 3 "normal" methods implement just fine and I get no errors at this stage, the problem is that I get red squiggy on IInsModule with the messages

  • CS0535: 'CSharpDriver' does not implement interface member 'IInsModule.Mod_Value[int].set'
  • CS0535: 'CSharpDriver' does not implement interface member 'IInsModule.Mod_Value[int].get'

I've tried every possible variation of a getter and setter I can think of but nothing has satisfied the interface. I don't know how to write it since IInsModule.Mod_Value[int].set and get are weird looking because of that int. Hope someone can tell me what to write based on the interface, thanks!

Xenofono
  • 169
  • 2
  • 9
  • https://stackoverflow.com/questions/6452391/exposing-indexer-like-properties-to-com – Hans Passant Sep 21 '21 at 14:03
  • 1
    This should work: `public void set_Mod_Value(int key, string value) { ... } public string get_Mod_Value(int key) => "blah";` – Simon Mourier Sep 21 '21 at 14:26
  • @SimonMourier Yeah that worked! Thank you! The generated property stub and the error message threw me off, didn't realize it was that simple. Thanks again! – Xenofono Sep 23 '21 at 06:13

0 Answers0