想在C#中自如地开关CDROM,可用以下代码,此为一个console程序。
using System;
using System.Text;
using System.Runtime.InteropServices;
class CloseCD
{
[DllImport( "winmm.dll", EntryPoint="mciSendStringA", CharSet=CharSet.Ansi )]
protected static extern int mciSendString( string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback );
public static void Main()
{
int ret = mciSendString( "set cdaudio door open", null, 0, IntPtr.Zero );
Console.ReadLine();
ret = mciSendString( "set cdaudio door closed", null, 0, IntPtr.Zero );
}
}
博客介绍了在C#中实现CDROM开关功能的方法,给出了一个console程序代码。通过使用System、System.Text和System.Runtime.InteropServices命名空间,调用mciSendString函数来控制CDROM的开关。
186

被折叠的 条评论
为什么被折叠?



