【问题标题】:ShellExecute print verb fails to print from 32 bit app on 64 bit windowsShellExecute 打印动词无法在 64 位窗口上从 32 位应用程序打印
【发布时间】:2012-03-20 16:32:23
【问题描述】:

我有一个客户在 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;
}

该程序在 32 位 Windows 版本(直至 Windows 7)上正常工作。该程序只需在命令行上传递的第一个参数上运行打印动词。

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 位程序的常见文件类型上的常见动词是否永久损坏?

【问题讨论】:

  • 如果我从“开始”菜单中的“运行”提示符运行该命令,我会遇到卡住的过程。如果我从 elevated cmd 窗口运行该命令,则该过程不会卡住,但我看不到任何 UI。我使用的是 64 位 Windows 7。我怀疑你有 UAC 问题。
  • @AdrianMcCarthy 哪个命令?运行dll32?还是printme的编译版本? html文件存在吗?

标签: windows winapi shell-verbs


【解决方案1】:

原来问题出在 ShellExecute 的最后一个参数上。虽然 0 工作了多年,但在这种情况下,它现在需要 SW_SHOW 才能为打印动词正确运行。也许最近的 Windows 更新改变了这种行为?

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 2010-10-18
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多