【问题标题】:How to check the result of PrintUIEntry call如何检查 PrintUIEntry 调用的结果
【发布时间】:2015-09-10 14:47:54
【问题描述】:

我想使用PrintUIEntryW(属于printui.dll)在Windows 系统上安装打印机驱动程序。我的代码如下所示(伪)。

m = LoadLibrary(L"printui.dll");
printuientry = GetProcAddress(m, "PrintUIEntryW");
// set arg_string
printuientry(NULL, m, arg_string, SW_SHOW);

我可以检查函数的返回值或类似GetLastError() 的东西来检查所需的调用是否成功?此函数似乎没有 msdn 条目。

提前致谢。

【问题讨论】:

标签: winapi printing


【解决方案1】:

PrintUIEntry 记录在这里:

Rundll32 printui.dll,PrintUIEntry

rundll32 记录在这里:

INFO: Windows Rundll and Rundll32 Interface

最重要的是:

在您的 DLL 中,使用以下原型编写函数:

16 位 DLL:

void FAR PASCAL __loads EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

32 位 DLL:

void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

...

在 Windows NT、Windows 2000 和 Windows XP 上,Rundll32.exe 的行为略有不同,以适应 UNICODE 命令行。

Windows NT 首先尝试为 W 获取 GetProcAddress。如果找到此入口点,则假定原型为:

void CALLBACK EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);

这与 ANSI EntryPoint 相同,只是 lpszCmdLine 参数现在是一个 UNICODE 字符串。

如您所见,设计用于rundll32 的函数没有返回值。并且PrintUIEntry 没有记录为使用SetLastError() 进行错误报告。因此,在这种情况下,您不能进行任何类型的错误处理。您将不得不使用不同的 API 来报告错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多