.net - COM interop interface casting -
following this article, have translated c++ com class/interface declaration c# this:
[interfacetype(cominterfacetype.interfaceisiunknown), guid(ifaceguid)] public interface ifoo { void bar(); } [comimport, guid(classguid)] public class foo { } i use this:
var foo = new foo(); var ifoo = (ifoo)foo; ifoo.bar(); my question is, how can possibly work, considering foo doesn't implement ifoo (even @ runtime, typeof(foo).getinterfaces() empty) , user-defined conversions interfaces forbidden?
is special handling reserved com? c# specification have this?
comimport types treated differently compared "normal" .net classes, constitute runtime-callable wrapper around underlying com coclass. casting instance of 1 of these com interface type transparently mapped call object's implementation of com interface method iunknown.queryinterface.
if qi requested interface succeeds @ com level, c# cast succeed.
Comments
Post a Comment