1

I am working with the CDO COM DLL for handling .eml files. When I try to instantiate the MessengerClass class, VC#2010 tells me I have to instantiate using the interface e.g.

CDO.Message msg = new CDO.Message();

instead of

CDO.Message msg = new CDO.MessageClass();

How can this be? Wont all the functionality be missing from this instance? This article says to do the same thing. What am I missing? Does an interface still contain usable functionality?

svick
  • 236,525
  • 50
  • 385
  • 514
Nate
  • 919
  • 2
  • 9
  • 18

3 Answers3

1

The CDO.Message class exposes the IMessage, IBodyPart and IDataSource interfaces according to MSDN

This answer has more details on some of the C#/COM behind the scenes magic.

Community
  • 1
  • 1
Rob Walker
  • 46,588
  • 15
  • 99
  • 136
  • when viewing the Message interface definition in VC#2010 it contains [CoClass(typeof(MessageClass))], and MessengerClass is defined as a bunch of virtual functions. I'm confused. – Nate Aug 26 '12 at 22:24
1

The compiler translates new COMInterface() into actual COM code that looks up the COM class that implements the interface.

As I understand, COM interfaces do not have multiple implementations; instead, the runtime loads the implementation from appropriate DLL specified in HKCR\Classes{guid}.
(I don't know much about COM, so this may be inaccurate.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Just go to the CDO reference right click on it chose Properties and change the property of Embed Interop Types to False