How to create instance of MsftDiscMaster2 in C#
I was tinkering with the CD-burning API in the Windows Vista SDK, and one of the basic classes needed for that is MsftDiscMaster2. The MSDN example is in VBScript and does this to create an object of type MsftDiscMaster2:
Now, to port this to C-Sharp, the first thing that I tried was this:
Activator.CreateInstance(typeof(MsftDiscMaster2));
It showed me a runtime excption: Cannot create an instance of an interface.
However, when I try this round-about way, it works!
Microsoft.VisualBasic.Interaction.CreateObject("IMAPI2.MsftDiscMaster2", "");
So, how do I create an object that inherits from MsftDiscMaster2 in C#? What magic is Visual Basic doing that allows it to create an object out of an interface?
Solution: Just create an instance of the MsftDiscMaster2Class class. That's it... it is a concrete implementation of the MsftDiscMaster2 interface. Simple, isn't it?
Comments
Post a Comment