5

I have a COM object interface in midl like

interface InterfaceName : IDispatch
{
  [id(1)] HRESULT FunA(...);
  [id(2)] HRESULT FunB(...);
  [id(3)] HRESULT FunC(...);
}

Are the ids required to be consecutive? Or can I define it like

interface InterfaceName : IDispatch
{
  [id(1)] HRESULT FunA(...);
  [id(3)] HRESULT FunB(...);
  [id(5)] HRESULT FunC(...);
}

Compiling the second version seems to be fine but will there occur any problems at runtime?

chrizke
  • 458
  • 3
  • 10

1 Answers1

3

Actual id values are arbitrary numbers. They do not have to be consecutive; they just have to be unique. Zero and negative values are, by convention, reserved for certain special methods. Apart from that, there are no rules.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85
  • Does there exist any (online)reference for this rule? – chrizke Aug 03 '14 at 18:09
  • For which one? For non-requirement of IDs being consecutive? You can't really expect every non-requirement to be documented - there's an infinite number of them. – Igor Tandetnik Aug 04 '14 at 00:45
  • Well, that's just common sense. If you were allowed two methods with the same ID, how would `IDispatch::Invoke` know which one to call? Maybe there's a piece of documentation that states this explicitly, but I'm too lazy to go hunt for it. – Igor Tandetnik Aug 04 '14 at 13:56