Enumerating Specific Items You Care About

If you've run DxDiag, or even the sample app from the DirectX SDK, you know that enumerating everything that DxDiag knows about can take quite some time. What if you don't care about the vast majority of the stuff listed, and only want to maintain information on a small subset of items? Luckily, the diagnostic namespace can be used for this as well.

Let's say the first thing you wanted to know was what version of DirectX the system running your application was using. No need to go through all of the work enumerating everything when you only care about something so simple. Here is the code you would use to determine this:

 Container parent = new Container(false); Container child = parent.GetContainer("DxDiag_SystemInfo").Container; int dxVersionMajor = (int)child.GetProperty("dwDirectXVersionMajor").Data; int dxVersionMinor = (int)child.GetProperty("dwDirectXVersionMinor").Data; string dxVersionLetter = (string)child.GetProperty("szDirectXVersionLetter").Data; Console.WriteLine("DX Version:{0}.{1}{2}",dxVersionMajor,dxVersionMinor,dxVersionLetter); 

Here, we create the root container (without any WHQL information). We then get a child container from this root named DxDiag_SystemInfo. We then get three different properties of the DirectX version: the major version number, the minor version number, and then any "letter" associated with this version of DirectX (since DirectX is notorious for releasing versions such as DX8.1b).

You may be wondering where these property names came from, and although it isn't obvious initially, all of these names are discoverable. As we were enumerating the properties and containers, you can see that we printed out the name of each as we went. You would need to write the enumeration code at the very least (or use the DX SDK sample) to determine the container and property names for the information you want to get.

The property names prefixes also give you the default data type for the object. They are all given names that match Hungarian notation for C developers. Items with the prefix "sz" denote strings. Items with the prefix "b" are Boolean values. All other prefix values denote integer values.

Using the Diagnostics namespace can be an invaluable way to help track down issues in your application. Your application should use it for error reporting, at the very least for debugging purposes. It's even possible to use this in your shipping game to help support when trying to figure out why your game refuses to run on certain customers' computers. The time saved by detecting common errors (old outdated drivers, for example) and allowing support to fix them quickly is significant. Who knows, it's possible a bug could be found in your game that only happens on certain video cards; you wouldn't have been able to tell without getting this information from multiple customers having similar problems.

It's better to plan for problems early than to wait and be sorry later.



Managed DirectX 9 Graphics and Game Programming, Kick Start
Managed DirectX 9 Kick Start: Graphics and Game Programming
ISBN: B003D7JUW6
EAN: N/A
Year: 2002
Pages: 180
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net