Windows XP and its successor Windows operating systems provide the Image Mastering API (IMAPI) for burning CDs. Starting with
IMAPI version 2 (the default for Windows Vista, but also available from Microsoft as an upgrade for Windows XP Service Packs
2 and 3, and Windows 2003 Server), DVDs and Blu-ray media can be burned as well.
The shells of these operating systems provide a Component Object Model (COM) class whose ICDBurn interface (which is based on
IMAPI version 1) facilitates CD burning. More specifically, ICDBurn makes it easy to create data CDs (CDs that consist
of files and directories). ICDBurn doesn't support the creation of audio CDs.
ADVERTISEMENT
This article introduces you to ICDBurn by first presenting this COM interface's fundamentals. The article next shows you how
to access ICDBurn from the C, C++, and C# languages. Lastly, the article reveals ICDBurn's usefulness via a file-backup
utility that lets you select and burn files to one or more CDs.
Note
This article assumes a Windows XP platform and that you have a basic understanding of COM. To learn about COM, review
Wikipedia's Component Object Model entry, and follow this
entry's various links to external COM tutorials.
ICDBurn 101
XP's shell provides a shell folder extension class in shell32.dll. This COM class, identified via globally
unique identifier (GUID) fbeb8a05-beee-4442-804e-409d6c4515e9, presents the ICDBurn interface, identified via
GUID 3d73a659-e5d0-4d42-afc0-5121ba425c8d. These GUIDs are essential for creating a COM object from the
extension class, and for accessing this object via ICDBurn.
ICDBurn exposes three functions:
HRESULT HasRecordableDrive(BOOL *pfHasRecorder) scans the hardware looking for a CD burning device, and stores
a Boolean value in the memory location pointed to by pfHasRecorder to indicate the presence (TRUE) or absence
(FALSE) of a CD burner. This function returns S_OK if it succeeds.
HRESULT GetRecorderDriveLetter(LPWSTR pszDrive, UINT cch) stores the drive letter of the default CD burning
device in the memory location pointed to by pszDrive. The drive letter is stored as a string of wide characters
in the form x:\, where x is the actual letter. This function returns
S_OK if it succeeds.
HRESULT Burn(HWND hwnd) launches a wizard to guide the user through the burning process, and copies files and
directories from a special directory known as the staging area to a writable CD. The passed hwnd argument
identifies the parent window for each of the wizard's windows. If this function succeeds, it returns S_OK.
Note
COM interface functions typically return an HRESULT value (such as S_OK) to indicate a function's
success or failure. This value is represented by a constant beginning with S_ (success) or E_
(error/failure). Rather than compare the HRESULT value against a specific constant, C and C++ code can use COM's
SUCCEEDED() and FAILED() macros to generically test the value for success or failure. For C# and
other .NET languages, however, SUCCEEDED() and FAILED() aren't needed. This is due to the COM
Interop portion of the .NET Common Language Runtime (CLR) automatically transforming HRESULTs into
COMExceptions.
Before the Burn() function can copy the staging area's contents to a CD, a program must copy files and/or
directories to this special directory. The program identifies the staging area's location by invoking an appropriate shell
function. Although there are several functions from which to choose, I find it convenient to work with
SHGetFolderPath(), which has the following C prototype:
To retrieve the staging area's location, pass the following arguments to this function: a language-dependent null value to
hwndOwner and hToken, constant CSIDL_CDBURN_AREA to nFolder, constant
SHGFP_TYPE_CURRENT to dwFlags, and a language-dependent TCHAR array of maximum path
length characters to pszPath.
Note
According to Microsoft, CSIDL_CDBURN_AREA is a constant special item ID list value for the staging area.
Furthermore, CSIDL "values provide a unique system-independent way to identify special folders used frequently by
applications, but which may not have the same name or location on any given system. For example, the system folder may be
C:\Windows on one system and C:\Winnt on another."
In addition to its three functions, ICDBurn inherits the QueryInterface(), AddRef(), and
Release() functions from its IUnknown parent. C and C++ code can ignore the first two functions but must work
with Release(), whereas C# code can ignore all three functions because the CLR's COM Interop (discussed later)
automatically calls Release() for C# and other .NET languages.
Manipulating Society through Technology
Jeremy Bailenson, Director of the Virtual Human Interaction Lab at Stanford University, talks about virtual reality, avatars, Moore's law, how real world behaviors influence online reality, and societal manipulation through technology! >> Play video >> Read article >> See all videos