Problem open files/folders with ShellExecute

Dan Kegel dank at kegel.com
Fri Mar 7 12:20:04 CST 2008


Bruno Cabral wrote:
>how could i use ShellExecute() to open a folder in Kde or
>Gnome ? The best that i got is to open the wineefile with this:
>ShellExecute(handle, "open", "explorer", "path_to_folder", NULL,SW_SHOWNORMAL);
>And i try to open a file too(for example a mp3), but it do nothing too.
>ShellExecute(NULL, NULL, "path_to_mp3", NULL, NULL, SW_SHOW);
>Both examples work fine with all version of windows.

Wine really should make ShellExecute work just as you expect,
but I don't know how long it'll be until we get around to it.

For now, you can detect that you're running on Wine
(e.g. if getenv("LOGNAME") is not NULL),
and then use the command xdg-open to open the directory or .mp3 file.
To prove to yourself this works, try
  wine cmd /c z:\\usr\\bin\\xdg-open foo.mp3
or
  wine cmd /c z:\\usr\\bin\\xdg-open /usr

That will open the file or directory in the appropriate native app.
The only catch is that the path passed to xdg-open has
to be a Unix path.  You can use the executable winepath
to convert Windows paths to Unix paths.  To prove to yourself
this works, try this:

 wine cmd /c winepath c:\
This will output the Unix path,
/home/dkegel/.wine/dosdevices/c:/

And then you have to be careful about paths with spaces in them, etc.
It's a bit of a pain at the moment.

If you go down this route, put it in a helper function so you
can rip it out easily later.  (And so you can share the
helper function with others.)
- Dan

p.s. Related bug:
http://bugs.winehq.org/show_bug.cgi?id=3332



More information about the wine-devel mailing list