Have you ever wondered what goes on behind the scenes when XP burn CDs? How? would of course be the fist question you would have asked. The simple answer is: the ICDBurn Interface. With this article, I will demonstrate how to write data to a CD while utilising XP's ICDBurn Interface.
So, What Is this ICDBurn Interface I'm Talking About?
The ICDBurn interface has three main functions:
- To determine whether hardware capable of writing to CD is present on the system.
- To determine the drive letter of a CD writer device.
- To programmatically initiate a CD writing session.
Because of these functions, it has three methods to accomplish the above-mentioned tasks:
|Burn||Instructs data to be copied from the staging area to a writable CD.|
|GetRecorderDriveLetter||Retrieves the drive letter of a CD drive that has been marked as write-enabled.|
|HasRecordableDrive||Scans the system for a CD drive with write capability, returning TRUE if one is found.|
Table 1: ICDBurn Methods
Now, dig deeper into each of these functions' purpose.
The Burn method
As mentioned in Table 1, this function instructs the data to be copied from the staging area to a writable CD. All this function needs to work is a handle of the parent window of the user interface (UI); this gets supplied through its hwnd parameter.
What is the "Staging Area?"
The staging area is the temporary burn location for files waiting to be written to disk. So, when you select all the files and folders you want to burn to disk, they are copied to this temporary area, and from there, they are written to disk. Typically, the staging area has a default location of %userprofile%\Local Settings\Application Data\Microsoft\CD Burning; one can translate this to C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning.
For the Burn method to actually work, you need to determine precisely where the user's temporary burn folder actually is. You can achieve this through the use of the following APIs:
|SHGetFolderPath||Takes the CSIDL of a folder and returns the pathname|
|SHGetSpecialFolderPath||Retrieves the path of a special folder, identified by its CSIDL|
|SHGetFolderLocation||Retrieves the path of a folder as an ITEMIDLIST structure|
|SHGetSpecialFolderLocation||Retrieves a pointer to the ITEMIDLIST structure of a special folder|
|SHGetFolderPathAndSubDir||Accepts the CSIDL of a folder and returns the path to that directory, appending a user-provided subdirectory path|
Table 2: Staging Area APIs
If you (hopefully) read the Table 2, you would have noticed that I kept referring to the term CSIDL. Let me explain. 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. Table 3 shows the available CSIDLs:
|CSIDL_FLAG_CREATE||Combine this CSIDL with any of the following CSIDLs to force the creation of the associated folder.|
|CSIDL_ADMINTOOLS||The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.|
|CSIDL_ALTSTARTUP||The file system directory that corresponds to the user's non localised Startup program group.|
|CSIDL_APPDATA||The file system directory that serves as a common repository for application-specific data.|
|CSIDL_BITBUCKET||The virtual folder containing the objects in the user's Recycle Bin.|
|CSIDL_CDBURN_AREA||The file system directory acting as a staging area for files waiting to be written to CD.|
|CSIDL_COMMON_ADMINTOOLS||The file system directory containing administrative tools for all users of the computer.|
|CSIDL_COMMON_ALTSTARTUP||The file system directory that corresponds to the non-localised Startup program group for all users.|
|CSIDL_COMMON_APPDATA||The file system directory containing application data for all users.|
|CSIDL_COMMON_DESKTOPDIRECTORY||The file system directory that contains files and folders that appear on the desktop for all users.|
|CSIDL_COMMON_DOCUMENTS||The file system directory that contains documents that are common to all users.|
|CSIDL_COMMON_FAVORITES||The file system directory that serves as a common repository for favorite items common to all users.|
|CSIDL_COMMON_MUSIC||The file system directory that serves as a repository for music files common to all users.|
|CSIDL_COMMON_PICTURES||The file system directory that serves as a repository for image files common to all users.|
|CSIDL_COMMON_PROGRAMS||The file system directory that contains the directories for the common program groups that appear on the Start menu for all users.|
|CSIDL_COMMON_STARTMENU||The file system directory that contains the programs and folders that appear on the Start menu for all users.|
|CSIDL_COMMON_STARTUP||The file system directory that contains the programs that appear in the Startup folder for all users.|
|CSIDL_COMMON_TEMPLATES||The file system directory that contains the templates that are available to all users.|
|CSIDL_COMMON_VIDEO||The file system directory that serves as a repository for video files common to all users.|
|CSIDL_CONTROLS||The virtual folder containing icons for the Control Panel applications.|
|CSIDL_COOKIES||The file system directory that serves as a common repository for Internet cookies.|
|CSIDL_DESKTOP||The virtual folder representing the Windows desktop, the root of the namespace.|
|CSIDL_DESKTOPDIRECTORY||The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).|
|CSIDL_DRIVES||The virtual folder representing My Computer, containing everything on the local computer: storage devices, printers, and Control Panel.|
|CSIDL_FAVORITES||The file system directory that serves as a common repository for the user's favorite items.|
|CSIDL_FONTS||A virtual folder containing fonts.|
|CSIDL_HISTORY||The file system directory that serves as a common repository for Internet history items.|
|CSIDL_INTERNET||A virtual folder representing the Internet.|
|CSIDL_INTERNET_CACHE||The file system directory that serves as a common repository for temporary Internet files.|
|CSIDL_LOCAL_APPDATA||The file system directory that serves as a data repository for local (no roaming) applications.|
|CSIDL_MYDOCUMENTS||The virtual folder representing the My Documents desktop item.|
|CSIDL_MYMUSIC||The file system directory that serves as a common repository for music files.|
|CSIDL_MYPICTURES||The file system directory that serves as a common repository for image files.|
|CSIDL_MYVIDEO||The file system directory that serves as a common repository for video files.|
|CSIDL_NETHOOD||A file system directory containing the link objects that may exist in the My Network Places virtual folder.|
|CSIDL_NETWORK||A virtual folder representing Network Neighborhood, the root of the network namespace hierarchy.|
|CSIDL_PERSONAL||The file system directory used to physically store a user's common repository of documents.|
|CSIDL_PRINTERS||The virtual folder containing installed printers.|
|CSIDL_PRINTHOOD||The file system directory that contains the link objects that can exist in the Printers virtual folder.|
|CSIDL_PROFILE||The user's profile folder.|
|CSIDL_PROFILES||The file system directory containing user profile folders.|
|CSIDL_PROGRAM_FILES||The Program Files folder.|
|CSIDL_PROGRAM_FILES_COMMON||A folder for components that are shared across applications.|
|CSIDL_PROGRAMS||The file system directory that contains the user's program groups.|
|CSIDL_RECENT||The file system directory that contains shortcuts to the user's most recently used documents.|
|CSIDL_SENDTO||The file system directory that contains Send To menu items.|
|CSIDL_STARTMENU||The file system directory containing Start menu items.|
|CSIDL_STARTUP||The file system directory that corresponds to the user's Startup program group.|
|CSIDL_SYSTEM||The Windows System folder.|
|CSIDL_TEMPLATES||The file system directory that serves as a common repository for document templates.|
|CSIDL_WINDOWS||The Windows directory or SYSROOT.|
Table 3: CSIDL Descriptions
What a mouthful! As you can see, all of the system special folders are listed here.
The ITEMIDLIST structure defines an element in an item identifier list (the only member of this structure is an SHITEMID structure). An item identifier list consists of one or more consecutive ITEMIDLIST structures packed on byte boundaries, followed by a 16-bit zero value. An application can walk a list of item identifiers by examining the size specified in each SHITEMID structure and stopping when it finds a size of zero. A pointer to an item identifier list, is called a PIDL (pronounced piddle). Note, however, that it is unnecessary to use the ITEMIDLIST structure; because the PIDL is a long, it can be passed and referenced as such when implementing the APIs.
Now, move on to the GetRecorderDriveLetter method.
As mentioned in Table 1, this method retrieves the drive letter of a CD drive that has been marked as write enabled. Obviously, this method will need a parameter supplying you with the write-enabled CD drive, but it also includes another parameter that makes sure that the "drive letter parameter" is the valid size. Based on this, it either returns an error code, or the particular drive letter.
Based on its descriptive name, you can see that this method determines whether you indeed have a recordable device present. If it found one, it simply returns true; else, false.
A list of all the Windows Shell Interfaces and their functions can be found here: http://msdn.microsoft.com/en-us/library/bb774328(VS.85).aspx.