code to burn and read files from cd rom

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pajju1992
    New Member
    • Jan 2013
    • 3

    code to burn and read files from cd rom

    can anyone suggest me how can i burn and read data from cd rom in c# language.???
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    Bytes.com isn't a code or homework service, we're a community of like minded people who come together to help those who are willing to help themselves.

    Show us what you've tried and we will do everything we can to nudge you in the right direction but we will not just do the work for you.

    Comment

    • pajju1992
      New Member
      • Jan 2013
      • 3

      #3
      this is the code what i have now......

      Code:
      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);
          
      }
      Last edited by Meetee; Jan 9 '13, 08:38 AM. Reason: Use code tags <code/> around your code

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        And is there something wrong with the code? You haven't told us anything about it.

        Comment

        • pajju1992
          New Member
          • Jan 2013
          • 3

          #5
          No there is nothing wrong with the above code... it works properly..

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            So then this thread is resolved and you need no further assistance?

            Comment

            Working...