CPrintDialog doesn't see the printer

Hi,

I'm developing an MFC application using VS2010.
I noticed that the the printing in my application stopped to work.

So the releveant piece of code is here:
1
2
CPrintDialog PrintDlg(FALSE, PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_DISABLEPRINTTOFILE, this);
	if(PrintDlg.DoModal() == IDOK) 



When PrintDlg.DoModal() is executed it comes up with this message:
"Before you can perform printer-releted tasks such as page setup or printing a document, you need to install a printer. Do you want to install a printer now?"

When I press the 'Yes' button it comes with another error:
"Windows can't open Add Printer. The local print spooler service is not running. Please restart the spooler or restart the machine"

I have network printer installed as default, and I can print from any other application without a problem.

I'm using Windows 7, but I checked on Windows XP and it comes with the same error.

I tried to swap the above code with:
1
2
CPageSetupDialog psd(PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS | PSD_ENABLEPAGEPAINTHOOK, this);
if(psd.DoModal() == IDOK) 


but it does the same thing.

The Print Spooler service is running. Also I tried to create dummy app with just the piece of code above and it still comes with the same message.


Any ideas?
Use application wizard to create a new MFC project without touching the wizard, build and execute resulting application and the printing will work.
That's true - it's working in the new default MFC project.
So now the question is what is wrong with my old project and how can I fix it?
Look at the wizard generated code and try to reproduce it in your old project. It can't be hard to do it.
It's a bit erratic for me.
After I created the default MFC project and tried to print from it, without any changes to my old apps (or recompiling), the printing in them is working again.

So theoretically there is nothing to fix.

But I still don't know what has caused the problem in the first place, and how it fixed itself.

Can anybody explain it to me?
Topic archived. No new replies allowed.