Burning Disk from Application

Pernah membuat aplikasi CD Burner?

Beberapa bulan yang lalu, saya mendapat tugas dari kantor untuk membuat sebuah aplikasi yang akan disebarkan ke seluruh kantor cabang di Indonesia. Dan aplikasi ini harus bisa menggandakan diri sendiri (Burning) tanpa menggunakan aplikasi lain (Seperti Nero). Sebelumnya saya blom pernah membuat aplikasi yang seperti ini. šŸ˜¦

Akhirnya saya bergoogling ria untuk mencari informasi atau komponen yang copotable dengan delphi. Dalam hati, wah klo gak ada komponennya, bisa2 bikin wrapper sendiri, dan pasti butuh waktu lagi. Namun ternyata ada komponen tersebut dan bagusnya lagi it’s free. šŸ˜€ Namun sayang, saya lupa link original untuk mendownloadnya. šŸ™‚

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).

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#.

Contoh penggunaannya:

unit Unit1;


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

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

Form1: TForm1;

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

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

// Start burning


Untuk komponennya silahkan download disini. Selamat mencoba. šŸ˜€


One Response to “Burning Disk from Application”

  1. jokorb Says:

    Mas Nor, downloadnya kalau gak salah di http://www.enhanceie.com/delphi/XPBurn.htm.

    Saya juga seudah pake sejak 2005.
    Cuma kenap ya, di Vista ga’ mau jalan? Sharing info dong…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: