是这个代码gona工作燃烧CD ....? [英] is this code gona work for burning cd....?
本文介绍了是这个代码gona工作燃烧CD ....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用系统;
使用 System.IO;
使用 System.Runtime.InteropServices;
使用 System.Text;
class CSburnD
{
[DllImport( shfolder.dll)]
静态 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 ()失败);
else
Console.WriteLine( SHGetFolderPath返回值= + szPath);
Console.Read();
Guid CLSID_CDBurn = new Guid( fbeb8a05-BEEE-4442-804e-409d6c4515e9跨度>);
类型t = Type.GetTypeFromCLSID(CLSID_CDBurn);
if (t == null )
{
Console。 WriteLine( OS不支持ICDBurn );
Console.Read();
return ;
}
ICDBurn iface =(ICDBurn)Activator.CreateInstance(t);
if (iface == null )
{
Console。 WriteLine( 无法获取接口);
Console.Read();
return ;
}
bool hasRecorder = false ;
iface.HasRecordableDrive( ref hasRecorder);
Console.WriteLine( HasRecordableDrive返回值= + 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);
}
当我运行代码时,会出现黑屏,我看不到任何错误。
解决方案
我不确定你的代码是否可行但是看看CP上的这篇文章,可能会给你更多关于你想要实现的信息。
使用C#和IMAPI2刻录和擦除CD / DVD /蓝光媒体 [ ^ ]
将文件刻录到CD的其他方法 [ ^ ]
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.
解决方案
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[^]
这篇关于是这个代码gona工作燃烧CD ....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文