Win32的PRINTDLG,PrintDlgEx,崩溃和诡异 [英] Win32 PrintDlg, PrintDlgEx, Crashing and quirkiness

查看:1375
本文介绍了Win32的PRINTDLG,PrintDlgEx,崩溃和诡异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我任务是解决以下问题:在64位计算机上运行时,我的应用程序崩溃时的 PRINTDLG()函数被调用。

挖掘和扯头发后,我决定最好的解决方案是大哥哥,的 PrintDlgEx()

这样做解决了一个问题(它不再崩溃!),但导致另一个。当我执行code,它的不可以显示打印对话框,只返回一个成功code,并给了我所有的信息,我的默认打印机。我需要此功能以显示标准的打印设置窗口,我不知道到底如何做到这一点。下面显示的是我试图用得到我的对话框中显示的样本值。

有什么想法?先谢谢了。

  //初始化PRINTDLGEX结构。
pd2.lStructSize = sizeof的(PRINTDLGEX);
pd2.hwndOwner = wnddata-> wnd.hnd;
pd2.hDevMode = NULL;
pd2.hDevNames = NULL;
pd2.hDC = NULL;
pd2.Flags = PD_RETURNDC | PD_COLLATE;
pd2.Flags2 = 0;
pd2.ExclusionFlags = 0;
pd2.nPageRanges = 0;
pd2.nMaxPageRanges = 10;
pd2.lpPageRanges = NULL;
pd2.nMinPage = 1;
pd2.nMaxPage = 1000;
pd2.nCopies = 1;
pd2.hInstance = 0;
pd2.lpPrintTemplateName = NULL;
pd2.lpCallback = NULL;
pd2.nPropertyPages = 0;
pd2.lphPropertyPages = NULL;
pd2.nStartPage = START_PAGE_GENERAL;
pd2.dwResultAction = 0;
PDRC = PrintDlgEx(安培; PD2);


解决方案

您最有可能获得E_INVALIDARG的返回code,因未能读小字上的 PRINTDLGEX 结构。具体来说,它说:如果没有指定PD_NOPAGENUMS标志,lpPageRanges必须是非NULL。

与PRINTDLG / PrintDlgEx根本问题是由于对你的WinMain缺少属性。你需要标记的WinMain为[请将STAThreadAttribute],表明您的COM线程模型是单线程单元。其他的线程模型可能工作,但我不能肯定地说。

I'm tasked with solving the following issue: My application crashes when running on a 64 bit machine when the PrintDlg() function is called.

After digging and hair pulling, I've decided the best solution is to replace the original calls of PrintDlg() with its bigger brother, PrintDlgEx().

Doing so fixes one problem (it no longer crashes!), but causes another. When I execute the code, it is not showing the print dialog, just returning a success code, and giving me all of the information for my default printer. I need this function to show the standard "print setup" window, I don't know how the heck to make it happen. Shown below are the sample values I'm trying to use to get my dialog to show.

Any thoughts? Thanks in advance.

//  Initialize the PRINTDLGEX structure.
pd2.lStructSize = sizeof(PRINTDLGEX);
pd2.hwndOwner = wnddata->wnd.hnd;
pd2.hDevMode = NULL;
pd2.hDevNames = NULL;
pd2.hDC = NULL;
pd2.Flags = PD_RETURNDC | PD_COLLATE;
pd2.Flags2 = 0;
pd2.ExclusionFlags = 0;
pd2.nPageRanges = 0;
pd2.nMaxPageRanges = 10;
pd2.lpPageRanges = NULL;
pd2.nMinPage = 1;
pd2.nMaxPage = 1000;
pd2.nCopies = 1;
pd2.hInstance = 0;
pd2.lpPrintTemplateName = NULL;
pd2.lpCallback = NULL;
pd2.nPropertyPages = 0;
pd2.lphPropertyPages = NULL;
pd2.nStartPage = START_PAGE_GENERAL;
pd2.dwResultAction = 0;
pdrc = PrintDlgEx  (&pd2);

解决方案

You are most likely getting a return code of E_INVALIDARG, due to failure to read the fine print on the PRINTDLGEX structure. Specifically, it says "If the PD_NOPAGENUMS flag is not specified, lpPageRanges must be non-NULL."

The underlying problem with PrintDlg / PrintDlgEx is due to a missing attribute on your WinMain. You need to tag WinMain as [STAThreadAttribute] to indicate that your COM threading model is single-threaded apartment. Other threading models MAY work, but I can't say for sure.

这篇关于Win32的PRINTDLG,PrintDlgEx,崩溃和诡异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆