简体   繁体   English

ShellExecute打印动词无法在64位Windows上从32位应用程序打印

[英]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. 我有一个32位程序,该程序已由客户在64位Windows上安装。

There appears to be a problem with using ShellExecute and the print verb in that configuration. 在该配置中使用ShellExecute和print动词似乎存在问题。 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. 该程序可以在Windows 7或更高版本的32位Windows上正常运行。该程序只需在命令行中传递的第一个参数上运行打印动词即可。

printme Page1.htm 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" HKEY_CLASSES_ROOT \\ htmlfile \\ shell \\ print \\ command包含REG_EXPAND_SZ类型的默认值,其中包含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. 如果运行以下命令rundll32 c:\\ windows \\ system32 \\ mshtml.dll,PrintHTML“ Page1.htm”,则会成功显示打印对话框。

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. 但是,运行我的程序时会闪烁,但是打印对话框永远不会出现,并且C:\\ Windows \\ sysWow64 \\ rundll32.exe的停止副本位于进程管理器中,该文件永远不会完成。

Is there a workaround, or is ShellExecute permanently broken for common verbs on common file types from 32 bit programs on 64 bit windows? 有没有解决方法,或者对于64位窗口上32位程序中的通用文件类型的通用动词,ShellExecute是否被永久破坏?

It turns out the problem is the last parameter of ShellExecute. 原来问题出在ShellExecute的最后一个参数上。 While 0 worked for years, it now requires SW_SHOW to function correctly for the print verb in this case. 尽管0可以使用多年,但现在在这种情况下,它要求SW_SHOW对于打印动词才能正确运行。 Perhaps a recent windows update changed the behavior? 也许最近的Windows更新改变了行为?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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