ShellExecute打印谓词无法在64位窗口上从32位应用程序打印



我有一个32位程序,它是由一位客户安装在64位窗口上的。

在该配置中使用ShellExecute和print谓词似乎有问题。首先是我的测试程序。

// 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 = %08xn", retVal);
    printf("LastError = %08xn", GetLastError());
    return 0;
}

此程序在32位windows版本(最高可达Windows7)上正常工作。该程序只是在命令行上传递的第一个参数上运行print谓词。

printme Page1.htm

有关系统的注册表设置如下:

HKEY_CLASSES_ROOT\htmlfile\shell\print\命令包含REG_EXPAND_SZ类型的默认值rundll32.exe%windir%\system32\mshtml.dll,PrintHTML"%1"

如果我运行以下命令rundll32 c:\windows\system32\mshtml.dll,PrintHTML"Page1.htm"打印对话框成功显示。

然而,运行我的程序会闪烁,但打印对话框从未出现,并且C: \Windows\sysWow64\rundll32.exe在进程管理器中,它永远不会完成。

是否有解决方法,或者ShellExecute是否永久中断了64位窗口上32位程序中常见文件类型上的常见谓词?

原来问题是ShellExecute的最后一个参数。虽然0工作了多年,但在这种情况下,它现在要求SW_SHOW正确地为打印谓词工作。也许最近的windows更新改变了行为?

最新更新