3

The DispId attribute can be passed certain values which confer specific meaning to anyone consuming your COM object.

e.g., here is one example.

Typical advice seems to be to just hardcode whichever "magic number" suits your purpose. But since .NET included the DispIdAttribute I was expecting a list of constants to go along with it - but haven't been able to find one. Does such a thing exist?

For the record the DispId values I'm talking about are:

DISPID_COLLECT         -8    
DISPID_CONSTRUCTOR     -6    
DISPID_DESTRUCTOR      -7    
DISPID_EVALUATE        -5     
DISPID_NEWENUM         -4    
DISPID_PROPERTYPUT     -3    
DISPID_UNKNOWN         -1    
DISPID_VALUE            0

ref https://msdn.microsoft.com/en-us/library/windows/desktop/ms221242(v=vs.85).aspx

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • If I remember my old VB6 days, pretty sure those values were magic numbers in there too :/ – DavidG May 04 '18 at 16:41
  • I am almost certain there are none. Even the MSDN examples from your link just use plain integer literals – adjan May 04 '18 at 16:46
  • 1
    Only two of these are ever expected to be used by a client app. DISPID_VALUE indicates the default property, in C# that is the indexer. DISPID_NEWENUM indicates the iterator, in C# you automatically get it when you implement IEnumerator. These assignments are automatic without having to use [DispId], thus no corresponding declarations are available in the framework. – Hans Passant May 11 '18 at 21:29

1 Answers1

2

I just used .NET Reflector to search for "dispid" in all assemblies in the .NET framework. It would appear that there are no public consts or enums that expose these standard DISPIDs. There are a couple of internal classes -- System.Dynamic.ComDispIds and System.Windows.Forms.NativeMethods+ActiveX -- that expose these constants, but you cannot get at them without reflection.

Michael Gunter
  • 12,528
  • 1
  • 24
  • 58