1

我有一个客户在 64 位 Windows 上安装的 32 位程序。

在该配置中使用 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 = %08x\n", retVal);
    printf("LastError = %08x\n", GetLastError());
    return 0;
}

该程序在 Windows 7 之前的 32 位 Windows 版本上正常工作。该程序只需在命令行上传递的第一个参数上运行 print 动词。

printme Page1.htm

在有问题的系统上,注册表设置如下:

HKEY_CLASSES_ROOT\htmlfile\shell\print\command 包含 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 位程序的常见文件类型的常见动词是否永久损坏?

4

1 回答 1

0

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?

于 2012-03-21T22:12:12.297 回答