1

Two simple COM IDL file questions I can't seem to find answers for, even with searching MSDN and the general internet:

  1. Is there an interface attribute which lets me specify my interface is to be implemented by STA objects only, or is this a detail for my documentation alone? I already have [object, local] which I think is correct for non-remoting (in-process) COM objects.

  2. Do I need void in the parentheses of my method declarations (like in C) to specify no arguments? MSDN is inconsistent about this; so are header files. My own personal implementations of this interface will be in C.

Thanks.

andlabs
  • 11,290
  • 1
  • 31
  • 52
  • 1
    COM is full of underspecified things that ended up the way they are because of how common practice fell out in the early days of COM ... I see no harm in using `void` , and I don't see what that interface attribute would achieve. (If someone else wants to implement your interface good for them). The supported threading models is a property of the class, not a particular interface. – M.M Mar 06 '15 at 23:58
  • Ah, "property of the class" makes sense then. Thanks for both answers! – andlabs Mar 07 '15 at 00:04

1 Answers1

1

You are talking about the threading model you want to specify for your COM component. No, you cannot put that in the IDL, it is far too important. A client doesn't have to use your IDL, a scripting language like Javascript never will for example. It must go in the registry, in the CLSID key for your component. You want ThreadingModel = "Apartment" to request the client to provide an STA thread. If it is missing then COM assumes that by default.

Do keep in mind that this does not force the client programmer to provide one. If he favors MTA for some reason then COM will provide the STA thread to give your component as safe home. If your proxy makes it too slow to be usable then you do have a documentation requirement.

No HRESULT Method(void) in the IDL is not necessary, using HRESULT Method() is sufficient. Midl.exe doesn't care what language you use.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • In the setup I use, the threading model is specified in one of the .cpp files (actually, constructor parameter for the ATL-like base), and the self-registration code refers to it. I guess MSVC does something similar. – M.M Mar 07 '15 at 03:11