Finally, I cheated:
As the access to the CD player using MCI is reset once I've closed my program, I've created a console application:
- that remains hidden (with "#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")")
- that creates a dummy window to communicate with the calling app (with "hWnd=CreateWindowExA(0, class_name, "register_name", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);")
- that accepts 4 arguments in the command line: the letter of the CD player, the number of the first track to be played, the number of the last track and the HWND of the calling program
And then I launch it via CreateProcess from my main program. As it has the parent HWND, I "SendMessage" from it and as soon as the dummy window is created, to pass its HWND to the parent so the latter can SendMessage to the child too:
- for the parent to get the current position in the playing
- for the parent to get the length of the track
- for the parent to tell its child to Kill itself if the playing has been cancelled
- for the child to tell its parent that the song is over before lilling itself.
And it works, I can open the CD tray while it's playing, insert a new one and start with a new track with the right TOC... And it is transparent as the way I create my console app makes no window and nothing in the taskbar.
Perhaps it creates a little more delay between 2 different plays as the child app needs to be launched and the CD to be re-opened, but this is a 68kB prog so nothing unacceptable.
Thanks for your help
David