0
votes

Our software is failing on the first call to EndPage() when trying to print to an HP M506 printer using the specific driver. It doesn't fail when using the HP Universal Print Driver but our customer is reluctant to use that because they say it is slower. The code is maybe 15 years old and must have printed to hundreds of different printer types over that period.

It only fails if the printer is set as the default. Even when it is the default, switching to a different printer and then back again in the print dialog makes it work.

The customer is using Windows 7 and I can reproduce the problem on Windows 7 (they have lent us one of their printers). They have tried it on Windows 10 where they say it also fails; I can't reproduce it on Windows 10 (or Windows 8.1).

The call to EndPage() is returning -1 when it fails - as far as I'm aware there is no extended error information for this. The code is using PrintDlg(); I've tried PrintDlgEx() but it made no difference.

When it is going to fail, the DriverVersion and DriverExtra fields in the DEVMODE structure after returning from PrintDlg() are both zero, which I would guess is an indication that something has already gone wrong at that point.

The application is currently built with Visual Studio 2013, is written in C/C++ (with a bit of C# thrown in, but no C# code needs to be executed to get the problem) and is 32-bit. All the versions of Windows mentioned above are 64-bit.

1
You cannot get a diagnostic for printer api errors, the printer driver is supposed to take care of it. If there is no popup and nothing in the Application log then you have no way to find out what went wrong. Getting support from HP for this problem is going to be a long shot but what it takes. - Hans Passant

1 Answers

0
votes

Well, I've "fixed" it. Before the call to PrintDlg() the DEVMODE was being allocated with GlobalAlloc(), locked with GlobalLock(), had some fields set and then unlocked with GlobalUnlock(). I removed the GlobalLock() and GlobalUnlock() and it now works.