The following code illustrates how to acquire and then release a device.
MCI_GENERIC_PARMS mciGenericParms; /* Info data structure for cmd */ USHORT usDeviceID; HWND hwndMyWindow; /* Assign hwndCallback the handle to the PM Window routine */ mciGenericParms.hwndCallback = hwndMyWindow; /* Acquire the device for exclusive access and assume it is inactive */ mciSendCommand(usDeviceID, /* Device ID */ MCI_ACQUIREDEVICE, /* MCI acquire device message */ MCI_NOTIFY | MCI_EXCLUSIVE, /* Flags for this message */ (PVOID) &mciGenericParms, /* Data structure */ 0); /* No user parm */ /* Device will be exclusively acquired once MM_MCIPASSDEVICE */ message is received indicating MCI_GAINING_USE */ /* Perform whatever operations require exclusive access to device */ mciSendCommand(usDeviceID, /* Device ID */ MCI_RELEASEDEVICE, /* MCI release device message */ MCI_NOTIFY, /* Flag for this message */ (PVOID) &mciGenericParms, /* Data structure */ 0); /* No user parm */