Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
 
class CSburnD
{
    [DllImport("shfolder.dll")]
    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");
        else
            Console.WriteLine("SHGetFolderPath return value = " + szPath);
        Console.Read();
       
        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");
            Console.Read();
            return;
        }
 
        ICDBurn iface = (ICDBurn)Activator.CreateInstance(t);
        if (iface == null)
        {
            Console.WriteLine("Unable to obtain interface");
            Console.Read();
            return;
        }
 
        bool hasRecorder = false;
        iface.HasRecordableDrive(ref hasRecorder);
        Console.WriteLine("HasRecordableDrive return value = " + hasRecorder);
        Console.Read();
        if (hasRecorder)
        {
            StringBuilder driveLetter = new StringBuilder(4);
            iface.GetRecorderDriveLetter(driveLetter, 4);
            Console.WriteLine("GetRecorderDriveLetter return value = " +
                              driveLetter);
            Console.Read();
            iface.Burn((IntPtr)0);
        }
    }
}
 
[ComImport]
[Guid("3d73a659-e5d0-4d42-afc0-5121ba425c8d")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ICDBurn
{
    void GetRecorderDriveLetter([MarshalAs(UnmanagedType.LPWStr)]
                                StringBuilder pszDrive, uint cch);
    void Burn(IntPtr hwnd);
    void HasRecordableDrive(ref bool HasRecorder);
    
}
 
When I run the code, a black screen appears and I cannot see any errors.
Posted 8-Jan-13 20:33pm
Edited 8-Jan-13 21:10pm
v3
Comments
Sandeep Mewara at 9-Jan-13 2:43am
   
Run it and see by yourself?
Peter_in_2780 at 9-Jan-13 2:45am
   
Beat me to it
GeekBond at 9-Jan-13 2:53am
   
Seeing the title, one would just be like, duh.... run the code.
pajju1992 at 9-Jan-13 2:45am
   
it gives some error so can u correct it..??
Mycroft Holmes at 9-Jan-13 2:52am
   
That is your job, if you post the errors you may get some help, asking someone else to do your job is counterproductive!
GeekBond at 9-Jan-13 2:54am
   
Exactly.
GeekBond at 9-Jan-13 2:52am
   
What are the errors did it gave you? Can you please post it on here? :wink: we can't see your screen you know?
 
Plus, next time, click the reply button next to the comment of the person you want to reply to, the user gets a notification and that helps him/her to get to you faster.
pajju1992 at 9-Jan-13 3:06am
   
when i run that program that black screens appears and if i press enter it ill dis sapper.so that i cant c the message what it shows.:(
GeekBond at 9-Jan-13 3:10am
   
Okay, question updated.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not sure if your code will work but take a look at this article on CP, might give you some more info on what you want to achieve.
 
Burning and Erasing CD/DVD/Blu-ray Media with C# and IMAPI2[^]
 
Other ways to burn files to CD[^]
  Permalink  
Comments
pajju1992 at 9-Jan-13 5:20am
   
well i saw all those things.... it dint workout..:(

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 676
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,198
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,470


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100