|
HiPerfProvider
The
HiPerfProvider sample demonstrates the basic framework of a high performance
provider. The WMI high performance API
is only supported on Windows 2000 platforms.
In
an attempt to model a real world environment, this sample contains a
data-source object (CSampleDataSource) that maintains 5 instances
(CSampleInstance) of a hypothetical object which has 5 counter values that will
each contain some contrived value. When a refresh is requested, the WMI objects
are updated from this virtual data-source, just as they would be in a real
world scenario. Note that the only time that HiPerfProvider updates the WMI
objects is during a refresh.
The
CHiPerfProvider class implements both the IWbemProviderInit and
IWbemHiPerfProvider interfaces. The IWbemProviderInit interface is the basic
interface that all providers must implement. The IWbemHiPerfProvider interface
contains a set of methods that create and manage refreshers.
The
CRefresher class is the class that implements the IWbemRefresher interface. The
refresher maintains a list of up to 10 enumerators that have been added to the
refresher as well as a mapping of ID’s to WMI object instances. When either an
enumerator or an instance has been added to the refresher, it is assigned an ID
for future reference. For a refresher, the ID is the first available element in
the m_apEnumerator array. The ID of an instance is generated incrementally
starting from a value greater than the maximum value that an enumerator ID can
be. The ID is then mapped to a WMI object within the refresher and the mapping
is stored in the m_apInstMap array. When an instance is removed from the
refresher, the mapping is simply removed.
The
only COM method in IWbemRefresher other than the standard set of COM methods is
Refresh. This method is called when the client has requested that the instances
within a refresher are to be updated and represents the only time that the
value of a WMI object within a refresher may be modified. The remaining
functions of CRefresher are primarily used for managing the refresher’s
contents.
NOTE:
The HiPerfProvider sample has
been designed to work with the HiPerfClient sample. Please see the HiPerfClient sample
documentation for instructions on building and using the client sample.
Building the Provider DLL
The DLL can be built
from the command line using NMAKE, or it can be built using Microsoft Visual
C++.
From the command line
in the sample installation directory, type the following:
NMAKE /f "Makefile"
From Microsoft Visual
C++:
1.
Select File +
Open Workspace
2.
Select the
BasicHiPerf.DSP file
Registering the DLL and Class
1.
The DLL must
be registered with COM. From the command line in the sample installation
directory, type the following:
REGSVR32 BasicHiPerf.dll
2.
You must also
compile the MOF in order to make the WMI CIMOM aware of the class. From the command line in the sample
installation directory, type the following:
MOFCOMP BasicHiPerf.MOF
At this point, you should be able to exercise the provider using the
HiPerfClient sample.
General Notes
Things
to remember when you're building your own WMI provider:
1.
WMI interfaces are defined
in wbemcli.h and wbemprov.h found in the wmi\include directory. You may #include both these files by
including just wbemidl.h located in the same directory.
2.
WMI interface CLSIDs are
defined in wbemuuid.lib. If you get unresolved externals in interfaces and
CLSIDs, this is what is missing.
3.
You'll need to link with
oleaut32.lib and ole32.lib to get the needed COM support.
4.
In the Link|Output
settings, specify 'wWinMainCRTStartup' as the entry point. This is per the
Unicode programming instructions.
5.
If you're using the makefiles, don't forget to set the Visual C++
environment variables. This is done by running VCVARS32.BAT.