I read your column in January 2004 about getting a drive letter and using the GetDriveType function to determine whether a disk is a CD (Drive_cdrom), but how do I know if the CD drive is a recording device? In addition, how can I write a file to a erasable CD? Windows XP allows you to drag and drop a file with Windows Resource management and write it to a CD. Can you tell if there is any way to implement it from my program without requiring users to buy third-party software, such as Nero or Roxio? Is there a related MFC class that can implement this function?
MFC does not provide a class for CD burning, but Windows Xp has built-in support for writing to CDs. If you are only copying files and directories, you can use the shell ' s Icdburn interface. If you want to burn audio or take a step closer to controlling your audio, a dedicated API is described below.
With Icdburn There are three steps, hasrecordabledrive scan the system can write CD drive, if found to return true. Getrecorderdriveletter returns the letter letter for the writable drive. The last burning instruction notifies Windows to copy data from the staging area to a writable CD. A "Staging Area" is a dedicated folder, usually "%USERPROFILE%\Local Settings\Application Data\Microsoft\CD Burning", but it should still call SHGetFolderPath and parameters Csidl_cdburn_area get the exact directory name. Developers often use SHGetFolderPath, because users will often manually or use tools such as Powertools/tweakui to change the burned directory.
The author wrote a very short class ccdburn to encapsulate Icdburn. This structure calls CoCreateInstance with Clsid_cdburn, and the reader can debug and run.
CCDBurn burner;
if (!burner.HasRecordableDrive()) {
printf("Oops—No recordable drive!\n");
} else {
CString dl =
burner.GetRecorderDriveLetter();
printf("Default Recorder drive letter =
%s\n", (LPCTSTR)dl);
}
The drive letter is the drive that starts the CD recording feature in the drive record properties. Only one drive can set this property. Assuming Hasrecordabledrive returns True, that is, the computer has at least one recordable CD drive, all you have to do is copy the file to the staging area, which is burning.
Because the author is very rigorous, I added another step getburnfolderpath, call SHGetSpecialFolderPath get a CString form of the burning file directory:
CString path = burner.GetBurnFolderPath();
Figure 1 CD-driven burn properties
If you want to burn music, or find other burning drives (there may be multiple), or get more detailed information: such as manufacturing or model, or drive is a CD-R or CD-RW? For this reason, Windows XP provides IMAPI to implement these features, which are abbreviations for the Image Mastering API and not to be confused with the messaging API mapi--used for e-mail. Alas! It's hard to remember these abbreviations. IMAPI provides a COM interface to look for machine drives and write data, or the latest RF probes tuned to shiny plastic discs. For an overview of the IMAPI interface information see Figure 2.
Because the conflict with COM will cause bigger problems, the author wrote a small class library, Imapitools, solve most of the problems. To illustrate how to use this class library The author also wrote a program cdinfo. Cdinfo displays information about the CD record body in the console window.
As long as mastered the IMAPI,CD, burning is not difficult. But IMAPI is very large, after finishing the foundation, then briefly say this question.
Figure 3 Cdinfo
First, Cdinfo creates an object to display the drive letter and burn path. Next, create Cdiscmaster to open IMAPI session:
CDiscMaster dm; // create IDiscMaster
if (!dm.Open()) {
printf("Oops: ...");
return;
}