INFO: Subclassing Nonabstract Windows Management Instrumentation (WMI) Classes (216941)



The information in this article applies to:

  • Microsoft Windows Management Instrumentation 1.0

This article was previously published under Q216941

SUMMARY

When you create a provider that subclasses nonabstract WMI classes, the instances that you provide must exist in the superclass.

MORE INFORMATION

Providers that provide instances subclassed from a nonabstract class cannot return any instances that do not exist in the superclass. (In fact, they can return them, however, they will be discarded instead of being returned to the client.)

Also, all superclass instances must be dynamic instead of static. Static instances of a superclass cannot be overridden. Instances of your subclass must always override instances that exist in the superclass. However, a subclass provider can (and frequently does) return fewer instances than the parent (even zero instances).

The following example schema shows two classes, Class1 and Class2, with their respective providers, Prov1 and Prov2 (even though the same provider could be used for both). Also, Class2 is a subclass of Class1:
[dynamic, provider("Prov1")]
class Class1
{
  [key]
  String MyKey;
}

[dynamic, provider("Prov2")]
class Class2 : Class1
{
  String MyNewProperty;
}
				
In this example, there are the following instances of each class:
Prov1: 

   Class1.MyKey="item1"
   Class1.MyKey="item2"
   Class1.MyKey="item3"
   Class1.MyKey="item4"

Prov2:

   Class2.MyKey="item1"
   Class2.MyKey="item3"
   Class2.MyKey="item5"
				
When using the IWbemServices::CreateInstanceEnumAsync method, the WBEM_FLAG_DEEP flag specifies an enumeration that includes all classes of the hierarchy. The WBEM_FLAG_SHALLOW flag includes only immediate instances of the specified superclass.

Now the providers will enumerate the following instances by using CreateInstanceEnumAsync. A deep enumeration of Class1 returns the following:
   Class2.MyKey="item1"
   Class1.MyKey="item2"
   Class2.MyKey="item3"
   Class1.MyKey="item4"
				
A shallow enumeration of Class1 returns the following:
   Class1.MyKey="item2"
   Class1.MyKey="item4"
				
NOTE: Shallow enumerations include only immediate instances, which are not overridden by a subclass provider. So, both providers are called to determine the proper enumeration.

An enumeration of Class2 returns the following:
   Class2.MyKey="item1"
   Class2.MyKey="item3"
				
Class2.MyKey="item5" is never returned because Prov1 does not enumerate Class1.MyKey="item5". According to object-oriented principles, because Class2 derives from Class1, each Class2 object "isa" Class1 object. Because Class1 is nonabstract, each object that "isa" Class1 object must be enumerated by Prov1.

REFERENCES

For more information, please see "Creating a Subclass" in the Windows Management Instrumentation section of the Platform SDK documentation.

Modification Type:MinorLast Reviewed:3/20/2004
Keywords:kbDSWManage2003Swept kbinfo kbWBEM KB216941