views:

45

answers:

2

Does anybody know how to initiate a DVD playback using a known drive letter from out of a C++ program.

For what's worth: I simply search for the windows explorer's play function which is located in the context menu when right-clicking a DVD drive...

Thx in advance, Axel

+1  A: 

You should be able to use ShellExecute for this; the verb for playing DVDs or CDs seems to be "play".

ShellExecute(NULL, "play", "D:\\", NULL, NULL, SW_SHOWNORMAL);
Luke
This unfortunately does not work: although 'play' seems not to be a valid verb (according to MSDN), the ShellExecute function complains, that there no application is associated with file "D:\" (or "D:"). (GetLastError()=1155=ERROR_NO_ASSOCIATION)
Axel
Works fine on my machine.
Hans Passant
Huh?! Could this be a feature of a newer Windows version than mine? (I tried XP and Vista...)
Axel
A: 

It's been too long since I used Windows for me to give you exact details, but you should be able to get some idea of what to do by diving into the explorer settings in regedit and checking what the "Play" context menu is actually doing.

As I remember, the context menu entries are defined in a subtree with a path something like HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/explorer/... but don't quote me on it.

ssokolow
Hmm... How about obtaining the command line from HKEY_CLASSES_ROOT/DVD/shell/play/command ?!
Axel
well this seems to work; although it involves lots of string cutting operations....
Axel
I did say I haven't used Windows in ages and that the path I was remembering probably wasn't completely correct. Given that the last Windows I used was WinXP roughly 6 years ago, I think "they both have letters" can be excused as close enough to count as only partially wrong. :P I'll wait and see what happens here and, if this comment thread doesn't prove useful over the next few days, I'll delete my answer to keep things clean.
ssokolow
That command is what ShellExecute("play") invokes; if it's not working for you then either the disc is not detected as a DVD or something is wrong with the command (points to something that doesn't exist, etc).
Luke