|
ObjPathParser
The ObjPathParser
sample contains code which parses CIM-style object paths. Its primary use is in building providers,
when implementing GetObjectAsync(). However,
it is generally useful when working with WMI in a variety of contexts.
The primary
illustration is in PATHTEST.CPP. The
main() function contains a complete example of how to parse an object path
using the C++ class CObjectPathParser.
The code of interest is:
ParsedObjectPath*
pOutput = 0;
wchar_t
*pPath = L"\\\\.\\root\\default:MyClass=\"keyval\"";
CObjectPathParser
p;
int
nStatus = p.Parse(pPath, &pOutput);
printf("Return
code is %d\n", nStatus);
if
(nStatus != 0)
return;
The rest of the code
simply dumps the parsed output.
The other files in the
project contain the sources for the lexer and the parser. These files require no other supporting
files, and are not dependent on flex, yacc, or other similar tools. The code is self-contained.
Building the ObjPathParser Sample
The sample 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 ObjPathParser.dsp file
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.