使用裝置名稱開啟簡單裝置
下列範例會使用 mciSendCommand 函式指定裝置名稱,以開啟 CD 音訊裝置。
UINT wDeviceID;
DWORD dwReturn;
MCI_OPEN_PARMS mciOpenParms;
// Opens a CD audio device by specifying the device name.
mciOpenParms.lpstrDeviceType = "cdaudio";
if (dwReturn = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE,
(DWORD)(LPVOID) &mciOpenParms))
{
// Error, unable to open device.
}
// The device opened successfully; get the device ID.
wDeviceID = mciOpenParms.wDeviceID;