WMI SDK Sample - MethProv

Windows Management Instrumentation SDK Sample

MethProv

This sample demonstrates the framework necessary to implement a methods provider. This provider supports methods for the class "TestMeth". The only method supported in this sample is named Echo. It takes an input string, copies it to the output string and places the length of the string in the method return value. Note that the method is marked as "Static" and so it can be executed using a path to either an instance of the class, or the class path.

The MOF definition of the MethProvSamp class is:

[dynamic: ToInstance, provider("MethProv")] class MethProvSamp

{

[implemented, static]

uint32 Echo([IN]string sInArg="default", [out] string sOutArg);

};

NOTE: The MethProv sample can be used in conjunction with another WMI SDK sample, MethCli, the sample method client. Please refer to the MethCli documentation for details. The MethProv provider sample can also be used separately with other WMI tools such as CIM Studio without building the MethCli 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 MethProv.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 MethProv.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 methprov.mof

Using Method Client Application (MethCli) to Access the Sample

In order to use the MethCli sample to test the MethProv sample, follow the instructions provided in the MethCli documentation to build and execute the MethCli sample method client.

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.