Feeds:
文章
留言

Archive for 十月 31st, 2005

今天ttch問了我一個關於系統音效設備的問題,因為當時在忙,問題記得不是很清楚,依稀是問我如何取得混音設備… 翻了一下手邊的資料得知可以透過 Microsoft 提供的 Multimedia SDK 來取得,簡單的說,只要透過兩個API函數就可以得到解答,其中一個是取得系統混音設備的數量 mixerGetNumDevs ,另一個是用來列舉系統的混音設備資訊mixerGetDevCaps ,因此,一個簡單的程式下完成如下:
 
Const MAXPNAMELEN = 32
Private Type MIXERCAPS
    wMid As Integer         ‘  manufacturer id
    wPid As Integer         ‘  product id
    vDriverVersion As Long  ‘  version of the driver
    szPname As String * MAXPNAMELEN   ‘  product name
    fdwSupport As Long      ‘  misc. support bits
    cDestinations As Long   ‘  count of destinations
End Type

Private Declare Function mixerGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function mixerGetDevCaps Lib "winmm.dll" Alias "mixerGetDevCapsA" ( _
                                                        ByVal uMxId As Long, _
                                                        pmxcaps As MIXERCAPS, _
                                                        ByVal cbmxcaps As Long) As Long

Private Sub Form_Load()
    Dim ctr As MIXERCAPS
    Dim count As Long
    count = mixerGetNumDevs()
    MsgBox "混音設備數量:" & count
    For i = 0 To count – 1
        ret = mixerGetDevCaps(i, ctr, Len(ctr))
        MsgBox ctr.szPname
    Next
End Sub
 

其他相關的API或與多媒體有關的可以參考 Microsoft Multimedia

Read Full Post »

 
今天在修正一個錯誤時發現,如果進行字串(切割)轉陣列時,如果空字("")串對你而言是無意義的,那如果你要取得"有意義"的陣列長度就要小心。
[PHP]
$arr = explode(‘,’, “);
echo count($arr); // 1
[Javascript]
var str = “;
var arr = str.split(‘,’);
alert(arr.length); // 1
 
因為空字串會成為陣列中的第一個元素,所以,會回傳陣列長度為 1,而非預期的 0,此時就會發生隱含的錯誤…

Read Full Post »