Click here to Skip to main content
13,248,562 members (85,413 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 16 Jan 2013

Burn CDs in C# With ICDBurn

, 18 Jan 2013
Rate this:
Please Sign up or sign in to vote.
Burn a CD using C#.


In contrast to C and C++, accessing ICDBurn from C# involves COM Interop (that part of the CLR that allows COM and .NET objects to interact with each other). This technology is visible in Listing 3's csburnd.cs source code via the System.Runtime.InteropServices namespace, the ICDBurn interface definition, and more.

Using the code

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

class CSburnD
    static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
                                      IntPtr hToken, int dwFlags,
                                      StringBuilder pszPath);

    const int CSIDL_CDBURN_AREA = 0x3B;

    const int SHGFP_TYPE_CURRENT = 0;

    public static void Main(string[] args)
        StringBuilder szPath = new StringBuilder(1024);
        if (SHGetFolderPath((IntPtr)0, CSIDL_CDBURN_AREA, (IntPtr)0,
            SHGFP_TYPE_CURRENT, szPath) != 0)
            Console.WriteLine("SHGetFolderPath() failure");
            Console.WriteLine("SHGetFolderPath return value = " + szPath);

        Guid CLSID_CDBurn = new Guid("fbeb8a05-beee-4442-804e-409d6c4515e9");

        Type t = Type.GetTypeFromCLSID(CLSID_CDBurn);
        if (t == null)
            Console.WriteLine("ICDBurn not supported by OS");

        ICDBurn iface = (ICDBurn)Activator.CreateInstance(t);
        if (iface == null)
            Console.WriteLine("Unable to obtain interface");

        bool hasRecorder = false;
        iface.HasRecordableDrive(ref hasRecorder);
        Console.WriteLine("HasRecordableDrive return value = " + hasRecorder);

        if (hasRecorder)
            StringBuilder driveLetter = new StringBuilder(4);
            iface.GetRecorderDriveLetter(driveLetter, 4);
            Console.WriteLine("GetRecorderDriveLetter return value = " +

public interface ICDBurn
    void GetRecorderDriveLetter([MarshalAs(UnmanagedType.LPWStr)]
                                StringBuilder pszDrive, uint cch);
    void Burn(IntPtr hwnd);
    void HasRecordableDrive(ref bool HasRecorder);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

prajwal rao
India India
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionCheck if Burn-Process was aborted Pin
mOx16330-Jul-14 23:14
membermOx16330-Jul-14 23:14 
QuestionWhat happens if i run this code Pin
wvd_vegt17-Jan-13 2:01
memberwvd_vegt17-Jan-13 2:01 
AnswerRe: What happens if i run this code Pin
prajwal rao17-Jan-13 2:07
memberprajwal rao17-Jan-13 2:07 
GeneralRe: What happens if i run this code Pin
wvd_vegt17-Jan-13 5:36
memberwvd_vegt17-Jan-13 5:36 
GeneralRe: What happens if i run this code Pin
prajwal rao17-Jan-13 19:23
memberprajwal rao17-Jan-13 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 18 Jan 2013
Article Copyright 2013 by prajwal rao
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid