2

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;
    }

    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) ; //| COINIT_DISABLE_OLE1DDE);

    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:

HKEY_CLASSES_ROOT\htmlfile\shell\print\command contains a default value of type REG_EXPAND_SZ containing rundll32.exe %windir%\system32\mshtml.dll,PrintHTML "%1"

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 the print dialog never appears, and a stalled copy of C:\Windows\sysWow64\rundll32.exe is in process manager, which never completes.

Is there a workaround, or is ShellExecute permanently broken for common verbs on common file types from 32 bit programs on 64 bit windows?

Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25
  • If I run that command from the Run prompt in the Start menu, I get the stuck process. If I run that command from an *elevated* cmd window, the process doesn't get stuck, but I don't see any UI. I using 64-bit Windows 7. I suspect you have a UAC issue. – Adrian McCarthy Mar 20 '12 at 17:11
  • @AdrianMcCarthy Which command? rundll32? or the compiled version of printme? Did the html file exist? – Anthony Wieser Mar 20 '12 at 17:24

1 Answers1

1

It turns out the problem is the last parameter of ShellExecute. While 0 worked for years, it now requires SW_SHOW to function correctly for the print verb in this case. Perhaps a recent windows update changed the behavior?

Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25