Click here to Skip to main content
14,970,700 members
Articles / Desktop Programming / ATL
Posted 6 Apr 2011

Tagged as


28 bookmarked

An eXtensible Car Description format with ATL COM

Rate me:
Please Sign up or sign in to vote.
4.83/5 (6 votes)
27 Mar 2012CC (ASA 3U)12 min read
Introduces the XCD format that describes cars as collections grouped by Make and Year, and provides an API ported into a COM library to access the collections.


How would you select a personal car? There are about 50 major car manufacturers that provide information car-by-car about their models, there are specialized sites too. Would it be time-saving and convenient to have in one file pictures and descriptions of all cars released by a specific manufacturer in a specific year? Say when you are interested in cars released by Honda in the year 2011, you need to download one file only and you can analyze specs on-line or off-line on your platform of choice. This article assumes a positive answer and defines an eXtensible Car Description or XCD format for describing cars in a collection that groups cars by Make (car manufacturer) and Year so that any one file with an extension .CAR has all relative pictures and quick specifications. The article provides an API for browsing CAR files on any platform compatible with Win32. In fact, a set of CAR files representing all car manufacturers is compact in size and easy to browse and analyze on any desktop or mobile platform. Samples of programs that read CAR files are available with the download.



The collections of car pictures and quick specs grouped by year and make are used in the Car Explorer program that provides an interface to download CAR files for free.

Image 1

The XCD format elaborates a format that keeps together in one file a set of general images and descriptions. The latter was used in several applications released by MSB LLC from 2005.

XCD Design Goals

The XCD format describes content of CAR files. The design goals for XCD are:

  1. One CAR file shall describe all cars for one Make and one Year (excluding submodels in the current version).
  2. A valid CAR file shall have pictures and quick specifications for all car models (from XCD v1.1).
  3. A valid CAR file shall have at least one car description.
  4. Car descriptions are in digest form according to single car description in the XML format.
  5. Any CAR file shall provide a unique string identifier within the application that uses it.
  6. Within the application scope, any car model in the CAR file shall have a unique string identifier (can be year plus picture title or programmatic).
  7. XCD shall support adding, editing, and deleting car pictures and descriptions in a CAR file.
  8. Keep valid CAR files small in size, typically less than 1 MB.
  9. Acceptance of XCD format at least by one car manufacturer.
  10. Free sharing of CAR files.

From goal 1 follows:

  1. all cars in any XCD collection are of the same Make and Year, and
  2. since Makes are the same, all cars in a collection are of the same Country, not considering scenarios when one Make can be assembled in different countries.

From goal 2 follows:

  1. If a model is missing in a collection, the collection is not a valid CAR file.
  2. If a picture is missing, or a quick spec is missing or is incomplete for one model in a collection, the collection is not a valid CAR file.

Notice that the phrase “all car models” refers to inclusion into a collection of cars of different models, but not of different trims, colors, not with different engines or optional equipment.

From goals 5 and 6 follows: if identifiers do not follow the design goals, the CAR file is not valid.

In fact, the third design goal is the result of 1 and 2.

Used Terminology

Throughout this article, the terms "CAR file" and "collection" mean the same thing as described in the XCD Design Goals. The words "should", "required", "shall", "optional" are to be interpreted as described in RFC 2119.

Sample Application

The sample applications (MFC, C#, VB) that come with this article are developed with VS 2008 and enable you to read CAR files. Essentially, they have the same visual interface (MFC sample has additional expandable features) and use functions of ATL COM’s library named XCD.dll, which is also developed with VS 2008, to access data in CAR files. Any automation-compatible client can access functions of the XCD library. Build first the XCD_COM project (if XCD.dll is copied - register it with regsvr32, but before registration, you probably need to run Microsoft Visual C++ 2008 SP1 Redistributable Package if your target system does not have Microsoft Visual C++ 2008 installed), and then build the XCD_Client_MFC project that uses the XCD library. You will find in the download the sample collection, and you can download additional CAR files from the Car Explorer site. Here is the dialog of the XCD_Client_MFC application:

Image 2

First, click the “Select CAR File” button to select a CAR file from a directory. The Collection area of the dialog shows information about the CAR file as a collection such as collection title, number of images in the collection, collection version. The Car area of the dialog shows information about a particular car in the collection: use spin control to select the next item in the collection. Every car in the collection has an image; click the “Show Picture” button to view the item’s image. Starting from XCD v1.1, each car in a collection is tagged with quick specification details. Select the car detail from the combo box and click the “Get Value” button to see its value. The combo box's item is referred as tag since car technical description can be represented as an XML file (XCD stands also for XML Car Description).

The MFC sample application has additional features. The “Get Data” button located in the expandable bottom area of the dialog shown when you click the “More” button provides an alternative to get all technical information for a car in the collection with a single call. The right expandable area visible with a click on the “Show Legend” button indicates function prototypes used for all related calls in the left area.

Object Model

The XCD library provides methods to read data in CAR files. As shown in the following logical diagram, it is a COM DLL with two objects: Collection and Car.

Image 3

The Collection object is designed to access information about a collection as a whole. A client application should set the location of a collection with the FFN property, where FFN stands for the Full File Name of the CAR file, before the object's methods can be used. The Collection object is put aside from the Car object as a different entity because of scenarios when an application needs to read only general information about a collection such as its title (string ID), its version strings, or verify if a file is a CAR file.

The methods of the Car object serve to read information about a specific car in a collection such as the car's picture (GetPicture), a particular feature of the car specification (GetValue), or the whole car specification in one call (GetData). Since every Car object method reads the FFN string set in the Collection object, or «uses» the Collection object as shown on the diagram, the Collection object must be created before the Car object. Technically, you can create the Car object without the Collection object, but it would make no sense since there is no way to set the location of a CAR file without the Collection object. This logical bond (composite aggregation) is depicted with the black diamond.

Initialization With Your Application

Any automation-compatible language can use the XCD library to access the methods and properties of its objects. Since the Car object’s methods read the FFN string set in the Collection object, the Collection object must be created before the Car object, as shown:


' Import description of the XCD library as XCD.tlb from XCD's COM project.
#import "XCD.tlb" no_namespace, raw_interfaces_only


m_pCollection = NULL;
CoCreateInstance(__uuidof(Collection), NULL, CLSCTX_INPROC_SERVER, 
                __uuidof(ICollection), reinterpret_castvoid**>(&m_pCollection));

' Set the location of CAR file.
             "C:\\Documents and Settings\\I'm\\My Documents\\");

m_pCar = NULL;
CoCreateInstance(__uuidof(Car), NULL, CLSCTX_INPROC_SERVER, 
                             __uuidof(ICar), reinterpret_cast<void** />(&m_pCar));

In the result, the m_pCar pointer is obtained for the Car object’s methods. Notice that the raw_interfaces_only attribute is used with the #import statement to handle the XCD API with relative HRESULTs. If the attribute is dropped, you would get return values directly. For example, instead of:

BSTR bstrCollectionTitle;
HRESULT hr = m_pCollection->GetTitle(&bstrCollectionTitle);

You should write:

BSTR bstrCollectionTitle = m_pCollection->GetTitle();

See the XCD_Client_MFC sample in the download for details.


Assuming that the reference to the XCD library is set in the project settings, the references to its objects are obtained as follows:

private XCD.Collection objCollection;
private XCD.Car objCar;

objCollection = new XCD.Collection();

' Set the location of CAR file.
objCollection.FFN = 
         "C:\\Documents and Settings\\I'm\\My Documents\\";

objCar =  new XCD.Car();

See the XCD_Client_CS sample for details.


Assuming that the reference to the XCD library is set in the project settings, the references to its objects are obtained as follows:

Dim objCollection As XCD.Collection ' enables IntelliSense
Dim objCar As XCD.Car ' enables IntelliSense

objCollection = New XCD.Collection

' Set the location of CAR file.
objCollection.FFN = 
    "C:\\Documents and Settings\\I'm\\My Documents\\"

objCar = New XCD.Car

Notice that a reference to an object in VB can be created in several ways, and it could also be created like:

Dim objCollection As Object
objCollection = CreateObject("XCD.Collection")


Dim objCollection = New XCD.Collection

However, if you want to see IntelliSence context help as you type, you should use the first method, called early binding. See the XCD_Client_VB sample for details.


The following table enumerates the methods and properties implemented in XCD. For strings, the BSTR type is used to enable the use of XCD with languages other than C++. In other words, XCD is automation-enabled. All methods return an HRESULT value as COM's default return type. Notice that the quick specs are available since v1.1 of XCD; if GetXCDVersion returns an empty string (this means v1.0 of XCD), only car pictures and titles are available.

ObjectFunction PrototypeDescription
Collectionput_FFN(BSTR bstrFFN /* in */)Sets the Full File Name of the CAR file to read.
GetTitle(BSTR* pbstrTitle /* out */)Reads the title of the collection.
GetCount(USHORT pnCount /* out */)Reads the number of items (cars) in the collection.
GetVersion(BSTR* bstrCollectionVersion /* out */)Reads the version of the collection.
GetXCDVersion(BSTR* pbstrXCDVersion /* out */)Reads the version of the XCD format.
IsCarFile(VARIANT_BOOL* pbCarFile /* out */)Verifies if the collection is a CAR file.
CarGetPictureTitle(USHORT nItem /* in */, BSTR* pbstrTitle /* out */)Reads the picture title for the nItem car in the collection.
GetPicture(USHORT nItem /* in */, IPicture** ppPicture /* out */)Returns the address of the pointer variable that receives the IPicture interface pointer for the nItem car in the collection, where IPicture is the standard COM interface that makes it possible to get information about a picture (get_Width, get_Height) and draw the picture on a specified device context (Render).
GetValue(USHORT nItem /* in */, BSTR bstrTag /* in */, BSTR* pbstrValue /* out */)

Reads the value of the specified tag (bstrTag) in the car specification for the nItem car in the collection. The possible names for bstrTag are: Year, Make, Model, Submodel, Type, Price, Country, Length, Width, Height, Weight, Power, Fuel, Clearance, Tank Volume.

This function has a disadvantage that in order to read all data for a car, you need to make more than 10 calls with different bstrTag names. In order to get the whole specification with one call, use GetData instead.

GetData(USHORT nItem /* in */, VARIANT* pData /* out */)Returns a pointer to the VARIANT structure that contains a SAFEARRAY of data representing the quick specification of the nItem car in the collection.

XML Car Description

A car description can be represented in XML form. The XCD format describes cars in two forms.

Quick XML Description

The first form takes a quick technical specification of a car and puts it into XML according to the following table as of XCD version 1.1:

SummaryYearSpecifies the year in which the car was manufactured.
MakeSpecifies the car maker (manufacturer).
ModelSpecifies the model of the car.
SubModelSpecifies the submodel of the car, often referred as trim.
TypeSpecifies the body type of the car such as Sedan, Coupe, Convertible, SUV etc.
PriceSpecifies the MSRP price of the car in US dollars, where MSRP is the Manufacturer's Suggested Retail Price.
CountrySpecifies the main country where the car is manufactured.
MeasuresLengthSpecifies the length of the car in inches.
WidthSpecifies the width of the car (mirrors folded) in inches.
HeightSpecifies the height of the car in inches.
WeightSpecifies the curb weight of the car in pounds.
EnginePowerSpecifies the engine's horsepower.
FuelSpecifies the type of fuel used by the engine such as gas, diesel etc.
MiscClearanceSpecifies the ground clearance of the car, which is the distance between the lowest point on the car and the road.
Tank_VolumeSpecifies the tank volume of the car in gallons.

Extended XML Description

The second form of XCD extends the XML description of a single car with the first form and describes all cars in a collection in the extended XML form:

<?xml version="1.0" encoding="Windows-1252"?>
  <Title>Peugeot 2011</Title>

<Car id="2011_Peugeot_207_CC">
  <Model>207 CC</Model>



  <Clearance>No data</Clearance>

<Car id="2011_Peugeot_NextModel">
<!-- Next car in the collection -->

In this way, XCD describes a collection (CAR file) in its header area between the tags <Collection></Collection> and enumerates all cars in the collection in its main area according to the first form of XCD. In addition, a car’s picture title (plus year) serves as string ID of a car within the XCD document, like <Car id="2011_Peugeot_207_CC">. You can see samples of XCD documents in both forms in the download.

Browsing and Analyzing Collections

What applications can be used to open and read CAR files? First, from a programmer's perspective, you can use the samples provided in the download, and tailor them as you wish according to the XCD description in this article. Second, as a user, you can use the Car Explorer program, which has more elaborated interfaces making it possible to compare and analyze cars from different collections, and also provides an interface to download CAR files for free. Can you edit or create CAR files? Yes, the MSB Wizard (versions are available for Windows 7, Vista, Windows XP) enables you to do that (just rename the CAR extension to MSS before editing, and rename it back to CAR to view with Car Explorer).

Conclusion and License

Some things take more prudence than the others. This is certainly about cars, especially at the point of making a decision. However, how does one select her or his favorite car? What options he or she has? Assuming that all basic information about all cars released by a car manufacturer in a certain year is kept in one file according to a uniform format and is easily accessible, you simply download one file to analyze and decide when you are interested in a certain Make of a specific Year. What can be more simple?

In this article, the specification for XCD format was described that facilitates answers on these questions. The XCD description and the code provided as download with this article are licensed under the Creative Commons License that includes option to build upon this work both non-commercially and commercially on the condition that you Attribute this work:

Creative Commons License

The CAR files or collections as described in this article are supposed to be shared freely, and selling them would be contrary to the terms.


This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-Share Alike 3.0 Unported License


About the Author

United States United States
No Biography provided

Comments and Discussions

QuestionOne of my solution Pin
Alex Ibraham15-Jan-15 1:29
MemberAlex Ibraham15-Jan-15 1:29 
QuestionCopyright Infringement, Rev. 2 with CPOL cannot be used or CPOL reference MUST be removed Pin
Stan_196423-Mar-12 1:12
MemberStan_196423-Mar-12 1:12 
QuestionWhy is the Debug solution configuration set up so that it builds the Release version of each project? Pin
Grump13-Apr-11 23:09
MemberGrump13-Apr-11 23:09 
AnswerRe: Why is the Debug solution configuration set up so that it builds the Release version of each project? [modified] Pin
Stan_196415-Apr-11 23:55
MemberStan_196415-Apr-11 23:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.