C#中呼叫系統API開啟和關閉光碟機

iDotNetSpace發表於2009-02-05

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

class CloseCD
{
 //API宣告

  [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 );//關閉光區
  }
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-545377/,如需轉載,請註明出處,否則將追究法律責任。

相關文章