NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

The Class Interface

All functionality and state on COM objects are encapsulated in interfaces, which expose the object's functionality and state through methods. COM objects in Visual Basic can expose properties that appear like any other Visual Basic property, but to C++ objects (and also in the Visual Basic runtime), these properties, too, are exposed through methods. For objects in the NGWS runtime, interfaces are optional: they can have public fields, properties, and methods that are exposed either directly on the object or through interfaces implemented on the object.

To COM clients, the NGWS runtime implements a dual interface that exposes all the public methods and properties of the NGWS class and its base classes, if any. This interface is commonly referred to as the class interface. The class interface has the same name as the class, prefixed with an underscore. For example, a NGWS class MyClass would implement a class interface named _MyClass.

Fields on a NGWS class are not exposed to COM clients.

For example, consider the following NGWS class:

public class Mammal // implicitly extends System.Object
{
   void  Eat();
   void  Breathe():
   void  Sleep();
}

The COM client can obtain a pointer to a class interface named _Mammal, which is described in the type library that the TlbExp utility generates for Mammal as follows:

[uuid(0000…0000), version(1.0)] 
library AnimalLib
{
   [odl, uuid(0000…0000), hidden, dual, nonextensible, oleautomation]
   interface _Mammal : IDispatch
   {
      [id(0x00000000), propget] HRESULT ToString([out, retval] BSTR* pRetVal);
      [id(0x60020001)] HRESULT Equals([in] VARIANT obj, [out, retval] VARIANT_BOOL* pRetVal);
      [id(0x60020002)] HRESULT GetHashCode([out, retval] long* pRetVal);
      [id(0x60020003)] HRESULT GetType([out, retval] _Type** pRetVal);
      [id(0x6002000d)] HRESULT Eat();
      [id(0x6002000e)] HRESULT Breathe([out, retval] long* p1):
      [id(0x6002000f)] HRESULT Sleep([out, retval] double* p1);
   }
   [uuid(0000…0000)]
   coclass Mammal 
   {
      [default] interface _Mammal;
   }
}

If the Mammal class did happen to implement one or more interfaces, the methods of the interfaces would also be available through the class interface, as well as through the interfaces themselves.

Because the class interface inherits IDispatch, late-bound clients can call the methods of the class interface through IDispatch::Invoke. They can also obtain complete type information about the NGWS class through IDispatch::GetTypeInfo.

The NGWS runtime will generate unique DISPIDs on demand for the methods and properties of the class. The DISPIDs are guaranteed to always be the same for any instance of the same version of the same class. The DISPIDs are used by IDispatch::Invoke and are supplied by IDispatch::GetIdsOfNames and by the type information obtained through IDispatch::GetTypeInfo.