5/20/2007 -- Note: The code provided here does not generally appear to work on Windows Vista. While the ICDBurn interface still exists, launching the Wizard always appears to return "There are no files to burn" despite the files appearing in the staging area. Investigation continues...

  TCDBurner

What is it?

The TCDBurner component allows your code to burn files to CDR/W discs on your Windows XP®/2003 system.  This component will NOT work on systems other than Windows XP/2003 systems (although it gives a nice error message back to your program).

Essentially, it is a simple, friendly wrapper around the XP CD-Writing wizard.

11/11/2003 NEW: Sample code now available for C# and VB6.  Those are bare-bones samples, but should get you started. 

Or, want to burn in C# or Delphi without using the Wizard?  See XPBurn.

Download

    Delphi 5/6/7    CDBurner.zip (18Kb)         [Works with D4; add FileCtrl to the Uses clause]

    C# / .NET      CSharpBurn.zip (33Kb)

    VB6/ActiveX  VB_XPBurn.zip (220Kb)

    Need C++?  See this site: http://www.coolshades.btinternet.co.uk/ICDBurn.htm

To install for Delphi, simply copy CDBurner.pas and CDBurner.dcr to a convenient place (e.g. \Delphi\LIB) and then choose the Component | Install Component menu option in Delphi.

To install for C# or VB, simply read the instructions in the .ZIP file.

License

The component is freely redistributable in compiled form to any party and it may be used and packaged along with any software.  The component may not be redistributed in source form, nor may it be distributed under any other license (e.g. GPL).  If you're providing a source distribution of your application, please offer the user a link to this page.

Why Free?

I figured I'd sell it (and buy my partner something nice for putting up with my late hours ;-) but she said that I should just give it away. 

But, if you'd like to donate to support the site, it's painless. Just click here.

How it was done

This was actually quite a pain. I started off by realizing that MS has probably exposed the functionality in XP. So, I searched on Google for "CD Burn site:msdn.microsoft.com" where I found the info about ICDBurn.

I saw that it lived in Shell32.DLL, so I tried simply importing that from Delphi. Unfortunately, the type library for it doesn't export (I'm kinda fudging the technical details here) the interface, so Delphi doesn't pick it up. I was banging my head against the wall, so I went back to MSDN's ICDBurn article.

From there, I learned which header file / .idl file contained the reference (it shipped with Visual Studio.NET and also is in the IE SDK). From there, I found the information on the object that implements this interface. I got the CLSID of the object, and instantiated it from Delphi. Success. Now, the only problem is that I only had the interface in IDL, which had to be converted to Delphi (since it couldn't be imported, as I mentioned above). This was a real pain, and entailed lots of access violations and internet research, as I figured out how each IDL parameter mapped to a Delphi parameter.
 
Later, I wrapped the Delphi6 code into an ActiveX object for VB6.  I also figured out a much simpler way to do this using .IDL for C#.

Feedback and Future Enhancements

Depending on community interest, I will most likely improve the helper functions.  I'll also eventually write a demo app to show how the unit works.

Also, while XP's Wizard is nice, it might be cool to go around it and write directly to the disc, eh?  Look here: XPBurn.

Bugs

    None known.  Yet


Developer's Guide

Sample Code

This example copies a folder and its subfolders to the root of the CD to be created.  Note that it does not use the AddFiles helper method on the CDBurner object, because the AddFiles method does not create nested folders.

unit Unit1;

interface

uses
Windows,shellapi, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, CDBurner;

type
TForm1 = class(TForm)
Button1: TButton;
CDBurner1: TCDBurner;
function CopyToCDBurner(FromDir,ToDir : string ) : boolean;
procedure Button1Click(Sender: TObject);
end;

var
Form1: TForm1;
implementation

{$R *.DFM}
// Perform Folder copy
function TForm1.CopyToCDBurnArea(FromDir,ToDir : string ) : boolean;
var
    lpFileOpStruct : TSHFileOpStruct;
begin
    lpFileOpStruct.wFunc := FO_COPY;
    lpFileOpStruct.pFrom := Pchar(FromDir+#0);
    lpFileOpStruct.pTo := Pchar(ToDir+#0);
    lpFileOpStruct.fFlags := FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR or FOF_SILENT;
    Result := not Boolean(SHFileOperation(lpFileOpStruct));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
// Copy a folder tree to the burn area
if not CopyToCDBurnArea('C:\FolderToAdd', cdBurner1.BurnArea ) then ShowMessage('Cannot find C:\FolderToAdd');

// Start burning
CDBurner1.StartBurn;
end;

end.

Component Guide

type TCDBurner = class(TComponent)
 

Major Functions

constructor Create(AOwner: TComponent); Pass a TForm in as the owner.  If you need a non-visual version, register, and we'll talk.
procedure StartBurn; First, copy any files specified with Add File or Add Folder to the staging area. 

Then burn the files in Windows XP's staging area to the disc.  If you'd like to automate this even further, use SendKeys to send a "NEXT" command to the Wizard Window

Read Only Properties

property LastError: String String containing the last error message generated by the component.
property Equipped: Boolean TRUE if system has WindowsXP and a compatible CD burner, FALSE otherwise.
property IsBurning: Boolean TRUE if the WindowsXP burn-wizard is currently active.
property BurnerDrive: String CDR path to which the files are burned; e.g. "D:\"
property BurnArea: String Local path of CD-burn staging area.  Usually %HOMEPATH%\Local Settings\Application Data\Microsoft\CD Burning

 

property FilesToBurn: TStringList read fFiles; String list containing the files you've added via Add Files and Add Folders method.
property BurnSize: Int64 read GetBurnSize; Size in bytes of files waiting to be burned.  Check this is below the size of a blank CD (650mb) before calling StartBurn.

Event Handler Properties

Type TBurnDoneEvent = procedure (iResult: Integer) of Object;

property OnBurnDone: TBurnDoneEvent; Assign an event handler to this

Returns 0 if the XP Burn wizard exited normally; Non-zero otherwise.  If nonzero, check LastError for more information, if available.

Helper Functions

These basic helper functions were added for those who don't want to deal with the file system on their own.  They may be updated to be more useful in future versions, if I get lots of registrations. ;-)

function AddFile(Filename: String): Boolean; Copy a file to the staging area.  Returns TRUE if added successfully.
function AddFolder(Path: String): Boolean; Copy all files in and beneath the given Path to the staging area.  Returns TRUE if added successfully.
function ClearFiles:Boolean; Delete all files in the staging area.  Returns TRUE if all files and folders were removed successfully.

WARNING:  This method will delete all files & folders in the staging area, including those that were already there.  Do not use this method carelessly, or you're going to have angry customers.

Hit Counter