Page 1 of 1

A way to get show:/win: working on Windows XP

Posted: 2013-11-21T21:04:33-07:00
by djd
Thanks to snibgo and Chris for sharing insights and knowledge guiding the following.

The short answer to the "win:" problem is described in the last few lines of this post, the long answer following here,
includes how it came to be that.

Here is the "win:" line from the original delegates.xml file included with
IM Version: ImageMagick 6.8.7-4 2013-10-26 Q16

<delegate decode="png" encode="win" spawn="True" mode="encode" command="cmd.ex
e /C start "%m" file:///"%i."" />

snibgo presented a modification of the same line, which is assumed to work, for Windows 7.

<delegate decode="png" encode="win" mode="encode" command="cmd.exe /C %%System
Root%%/System32/rundll32.exe "%%ProgramFiles%%/Windows Photo Viewer/PhotoVi
ewer.dll", ImageView_Fullscreen file:///%i" />

The line refers to "Windows Photo Viewer", a name similar to the XP viewer
"Windows Picture and Fax Viewer". But in the case of XP, that is just the name on viewer's
title bar. A program with a name similar to that cannot be found on XP. However, after
some research one can discover that the following command line will open the XP viewer.

C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_
ullscreen

The following will also open the XP viewer

C:\>cmd.exe /C %SystemRoot%/system32/rundll32.exe %SystemRoot%/system32/shimgvw
dll,ImageView_Fullscreen

where
C:\>echo %SystemRoot%
C:\WINDOWS

The XP viewer does not have a file menu, so if the viewer has been opened using the command line,
it is necessary to drop an image file icon onto the viewer window.

If an image extension has been Registered (associated) with "Windows Picture and Fax Viewer"
(Control Panel | Folder Options | File Types | Extension) then clicking on the file icon will open
the viewer. BMP images are often associated with the XP viewer.

You can also include the name of an image file at the end of the command line above, but it can
be tricky.

This will display the star.gif image

C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_F
ullscreen C:\star.gif

this will also display the star.gif image

C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_F
ullscreen C:\documents and Settings\All Users\star.gif

but this will not display the image or open the XP viewer

C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_F
ullscreen star.gif

and this also will not display the image or open the XP viewer

C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_F
ullscreen "C:\documents and Settings\All Users\star.gif"


This `strange' behaviour is explained by the peculiarities of Rundll32

http://support.microsoft.com/kb/164787

"There are 3 issues to consider carefully in the above command line:

1. Rundll or Rundll32 search for the given DLL filename in the standard
places (see the documentation for the LoadLibrary() function for
details). It is recommended that you provide a full path to the DLL to
ensure that the correct one is found. For best results, use the short
file name instead of the long file name to ensure that no illegal
characters will appear. Note in particular that this means a DLL in the
"C:\Program Files" folder should be converted to its short name.

2. The <dllname> may not contain any spaces or commas or quotation marks.
This is a limitation in the Rundll command line parser.

3. In the above command line, the comma (,) between the <dllname> and the
<entrypont> function name is extremely important. If the comma
separator is missing, Rundll or Rundll32 will fail without indicating
any errors. In addition, there cannot be any white spaces in between
the <dllname>, the comma, and the <entrypoint> function."

To be sure, it seems we require our file argument to be in short file name form.
How is that achieved? One reference is here:

http://stackoverflow.com/questions/1022 ... hort-filen
ame-using-cmd-exe

That is, create a batch file with an argument `%~s1'.

Thus we consider the following batch file

myview.bat

@echo off
C:\>C:\WINDOWS\system32\rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_F
ullscreen %~s1

C:\> myview star.gif % Works

C:\> myview C:\star.gif % Works

C:\> myview "C:\Documents and Settings\All User\star.gif" % Works

C:\> myview C:\Documents and Settings\All User\star.gif % Fails

The above seems to be reasonably consistent behaviour so we try introducing the batch file
into IM's delegates.xml file, changing the "win:" line (illustrated near the beginning of this post) to:

<delegate decode="png" encode="win" spawn="True" mode="encode" command="cmd.exe
/C ;myview.bat "%i"" />

and copy myview.bat into the IM folder, the same folder as delegates.xml
(usually C:\Program Files\ImageMagick).

Then we run a test:

C:\>cd "C:\Documents and Settings\All Users"

C:\Documents and Settings\All Users>convert -verbose -size 100x100 xc:red win:

C:\Documents and Settings\All Users>convert -verbose -size 100x100 xc:red win:
xc:red=>red XC 100x100 100x100+0+0 16-bit sRGB 0.000u 0:00.000
xc:red=>C:/WINDOWS/TEMP/magick-276cmfFShBENiwQ PNG 100x100 100x100+0+0 8-bit sRG
B 2c 266B 0.125u 0:00.155
cmd.exe /C ;myview.bat "C:/WINDOWS/TEMP/magick-276yuA0p96pwh6g"
xc:red=>win: PNG 100x100 100x100+0+0 8-bit sRGB 2c 266B 0.063u 0:10.500

It worked! "win:" can be used with Windows XP.

Perhaps there is a way to eliminate the batch file, but that is left as an exercise for the reader.