Instantiating COM interop classes
I had spoken with some microsoft people while I was troubleshooting a COM interop problem and they told me something interesting about using COM classes in .Net. When you use a COM class you should dimension it and instantiate it like this (let's say our COM object is "ABC" and it has one class, "xyz"):
Dim objXYZ As ABC.xyz
objXYZ = New ABX.xyxClass
Apparently when tlbimp creates the interop, it creates the class wrapper (xyzClass) AND a class interface (xyz). MS says to dim it as the interface type, but to instantiate it as the class type.
I have decompiled the interop file for a little COM that I wrote to see what the .net code looked like and I didn't get much out of it. There was the interface and the class. The interface (obviously) just had the method signatures, while the class had what seemed to be the actual methods. All the methods looked like this:
public virtual extern <methodname>...
I'm assuming that the "extern" keyword has something to do with the COM access part of it but I'm not sure.
Anyone have any idea why this is?
Peter
|