COM interface types. A quick glossary

by Matt 13. June 2007 06:24

Right. Let's brush away some cobwebs, and write this down so I don't have to google all over the web whenever I need a quick COM 101 refresher:

  • A custom or vtable interface is a COM interface that derives from IUnkown. It only supports early binding through the compiler's vtable.
  • A dispinterface is a purely IDispatch based interface. The methods defined in the IDL file are only callable via IDispatch::Invoke, and not via a vtable. These are usually used as event interfaces (i.e. you implement the interface on your object and pass it to another object that you want to receive events from). Knowing this explains why it's not a cardinal COM sin that Microsoft have been expanding DWebBrowserEvents2 for each release of Internet Explorer.
  • A dual interface is a COM interface that derives from both IUnknown and IDispatch - it's both a vtable interface and a dispinterface.
  • Expando objects implement IDispatchEx and allow you to add methods and properties at runtime. This is how JavaScript, VBScript and Internet Explorer allow you to expand script and HTML objects.

A type library can be used to store interface information. It can contain vtable layouts and the DispId's required to call IDispatch based interfaces.

You can implement IDispatch by hand, with a huge switch statement, if you want to, but remember that you'll need to crack the parameters out of arrays and stuff them back in again for the return value. 

Alternatively, you can let someone else do the heavy lifting for you and use an implementation of IDispatch which is based on a type library. (And seeing how one of the methods of IDispatch is to get a pointer to an ITypeInfo interface representing a type library - you might as well). This works by calling LoadTypeLib to get an instance of ITypeLib, then calling ITypeLib::GetTypeInfoOfGuid. The resulting ITypeInfo can be used to defer the interesting IDispatch methods (including Invoke). This is what ATL's IDispatchImpl does. It's interesting to note that the Invoke method will call vtable based methods on your interface. This is pretty good voodoo.

As far as I can make out, you could also use CreateStdDispatch to create an IDispatch interface for you, which essentially does the same thing as IDispatchImpl. Or, you can implement bits of IDispatch yourself and defer to methods such as DispInvoke and DispGetIDsOfNames.

If you want to support dispinterfaces, you can use ATL's IDispEventImpl. This is an implementation of IDispatch that doesn't require an implementation of each member on the dispinterface. It does this by using a map that routes DispId's to functions - ideal for an interface that doesn't actually have a vtable. You could even use IDispEventSimpleImpl if you didn't want to use a typelib.

Sheesh. It's nice that .net moves well away from all of this malarky, but it's still something that you need to know from time to time...


Comments (11) -

best suv 2011
best suv 2011
7/20/2011 10:34:58 PM #

Per il tuo bambino scegli Moncler. Una scelta di capi, estivi ed invernali, eccezionali. Tuo figlio sarà sempre alla moda e potrà muoversi in totale comodità.


photographe mariage paris
photographe mariage paris United States
6/8/2015 2:09:19 AM #

I have noticed that in unwanted cameras, unique detectors help to focus automatically. The actual sensors with some video cameras change in in the area of contrast, while others use a beam involving infra-red (IR) light, particularly in low light. Higher specification cameras often use a blend of both programs and will often have Face Priority AF where the digicam can 'See' any face as you concentrate only upon that. Many thanks for sharing your notions on this weblog.


Deena Hofer
Deena Hofer United States
1/15/2016 6:24:09 AM #

AWESOME!Can't wait for that, will be something to want to accomplish day by day, to do something AWESOME!


Lidia Loser
Lidia Loser United States
1/15/2016 7:19:29 AM #

I love the dolphin saving you one.


Selma Houzah
Selma Houzah United States
1/15/2016 8:29:43 AM #

Congratulations on your success! You deserve it for brightening all of my work days with something to be excited about.


Hilaria Rieff
Hilaria Rieff United States
1/15/2016 8:59:35 AM #

The dolphin saving you one is the best one!


Patrica Guccione
Patrica Guccione United States
1/17/2016 9:57:45 PM #

AWESOME!Can't wait for that, will be something to want to accomplish day by day, to do something AWESOME!


Irvin Dewinter
Irvin Dewinter United States
1/19/2016 3:04:11 AM #

Congratulations, Neil! I love this site and I know I'll love the book. Christmas, birthdays, Father's Day 2010  check!


Kylee Marett
Kylee Marett United States
1/20/2016 6:02:26 AM #

Hey, congratulations Neil. This site really is something special and it's been a pleasure to share it with my readership too. Looking forward to future awesome things, and I'll send any suggestions that are sufficiently awesome.


Odell Jirasek
Odell Jirasek United States
7/19/2016 4:08:08 PM #

You know therefore considerably when it comes to this subject, produced me for my part believe it from numerous varied angles. Its like men and women don’t seem to be fascinated except it’s one thing to do with Lady gaga! Your personal stuffs nice. At all times maintain it up!


Stephania Bukrim
Stephania Bukrim United States
3/14/2017 7:48:49 PM #

This is a awesome website with some awesome tips


Add comment

  • Comment
  • Preview


Month List


Comment RSS