Tuesday, 20 March 2012

ShellExecute print verb fails on WOW64

I have a 32 bit program that has been installed by a customer on 64 bit windows.

There appears to be a problem with using ShellExecute and the print verb in that configuration.  First my test program.

// printme.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "objbase.h"
#include <windows.h>

#include <shellapi.h>

int main(int argc, char* argv[])
if (argc != 2)
printf("Usage: %s file_to_print", argv[0]);
return 0;


HINSTANCE retVal = ::ShellExecute(NULL, "print", argv[1], NULL, NULL, 0); // don't ask, as the user can always cancel...
printf("RetVal = %08x\n", retVal);
printf("LastError = %08x\n", GetLastError());
return 0;

This program works correctly on 32 bit windows version up to Windows 7.  The program simply runs the print verb on the first argument passed on the command line.

printme Page1.htm

On the system in question, the registry is set up as follows:


If I run the following command
rundll32 c:\windows\system32\mshtml.dll,PrintHTML “Page1.htm”
the print dialog is successfully shown.

However running my program blinks, but nothing ever launches.

Process manager shows the following:

As you can see the selected bottom line is running the 32bit version, which never completes.  The 64 bit version run previously does work.

Is there any workaround?  Not that I’ve found yet.

1 comment:

  1. There is an error in the above code. The last argument to ShellExecute should be SW_SHOW.

    While the existing code worked for years, I think a recent windows update may have changed it.