Game Development Reference
In-Depth Information
The next attribute to cover is InterfaceType , which is used to explicitly set how a
managed interface is exposed to COM. Managed interfaces are exposed as dual to
COM by default, which offers the flexibility of late binding or the performance of
early binding. You can explicitly state that a managed interface can only be
exposed as IDispatch , only supporting late binding. The following example shows
this attribute.
public interface IMyComponentEvents
// …
Similar to the InterfaceType attribute, the ClassInterface attribute is used to spec-
ify how classes are wrapped for COM. By default, a boilerplate interface is gener-
ated for classes exposed to COM, but this can be turned off using this attribute if
a custom interface is desired. While the ability to automatically generate interfaces
may seem easy, their use is strongly discouraged. The positioning of methods can
change to the point where clients think they are calling one method, but are in fact
calling a completely different method. Explicitly defining a custom interface for
your components is the safe way around this problem. The following example
shows how to use this attribute so that no interfaces are generated automatically.
public class MyComponent : IMyComponent
// …
You can explicitly set the COM dispatch identifier ( DISPID ) for a member, property,
or field with the DispId attribute. The constructor for this attribute takes an inte-
ger that specifies the identifier to associate with the type. The following example
shows this attribute in action.
public interface IMyComponent
void CustomMethod1();
Search Nedrilad ::

Custom Search