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.
[Guid(“50B39BFD-FC05-4f28-AF75-084E0394A55E”),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
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.
[Guid(“9DB1F428-B027-408d-BEDF-6A8398F0AAF8”),
ClassInterface(ClassInterfaceType.None)]
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.
[Guid(“AB8C32F0-9DA1-4afb-8B91-E8B035412DBD”)]
public interface IMyComponent
{
[DispId(1)]
void CustomMethod1();
Search Nedrilad ::




Custom Search