C# COM, default property is throwing error no. 438

0

I am writing an ActiveX COM control in C#. In this control I have a property called 'Value', which I am trying to expose as default property.

Here is the Typelib definition:

[id(0x00000002), propget, bindable, requestedit, displaybind, defaultbind, helpstring("Returns/sets the current date.")]
HRESULT Value([out, retval] VARIANT* pRetVal);

[id(0x00000002), propput, bindable, requestedit, displaybind, defaultbind, helpstring("Returns/sets the current date.")]
HRESULT Value([in] VARIANT pRetVal);

The Property implementation is simple :

public object Value
        {
            get { return BaseControl.Value.Date; }
            set
            {
               DateTime dt;              
                //BaseControl is a DateTimePicker control.
               BaseControl.Value = DateTime.TryParse((value ?? "").ToString(), out dt) ? dt : DateTime.Today;
            }
        }

When using this control in VBA, I able to Set\Get the Value property like this

Private Sub Test()
    Me.DTPicker1.Value = Date - 5
End Sub

But when I am trying to use the default version,

Private Sub Test2()
    '/Default property access
    Me.DTPicker1 = Date - 5
End Sub

It throws the error,

438: Object doesn't support this property or method.

Any idea, why the default mode is not working?

c#
vba
com
activex
typelib
asked on Stack Overflow Oct 9, 2018 by cyboashu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0