简体   繁体   中英

ShellExecute print verb fails to print from 32 bit app on 64 bit windows

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM