"FlyGuy" <Manha
...@mstarmetro.net> wrote:
> [...] I've added code to attempt to change some of the
> printer parameters, but can't seem to get the correct
> results. [...]
A couple of things:
> char deviceName[128];
> char driverName[128];
> char portName[128];
These should be 256 in length and initialized:
char deviceName[ 256 ] = { 0 };
char driverName[ 256 ] = { 0 };
char portName [ 256 ] = { 0 };
> unsigned int hDeviceMode;
While it most likely makes no difference, this is technically
a THandle:
THandle hDeviceMode;
> DEVMODE* pDevMode; // pointer to DEVMODE struct
> Prntr->GetPrinterA(deviceName, driverName, portName, hDeviceMode);
I'm uncertain about GetPrinterA so I would suggest that you
use GetPrinter. However, there is a known issue with TPrinter
in that it's Handle is not always valid so you need to insert
a line above the call to GetPrinter:
Printer()->PrinterIndex = x;
where x is a valid printer index. It's been more than a year
since I tested this and my notes are no longer clear. It looks
like x can not be -1 which under other conditions is a valid
value to restore the default printer. I also suspect that you
may have to use a non-default printer. You can just install a
generic printer which won't require and disks and then use the
control panel to change the default to the generic.
> pDevMode = (DEVMODE*)GlobalLock((void*)hDeviceMode);
I'm confident that this was the problem because the call to
GetPrinter was returning a bad hDeviceMode. Actually, not bad
but rather incorrect.
BTW : You really should be using C++ casting here.
> GlobalUnlock((void*)hDeviceMode);
I'm reasonably sure that you need to call SetPrinter after you
unlock but in my sample, the ADeviceMode parameter is set to
NULL. This causes concern for me but you should be able to
figure it as long as you're aware of it.
> I'm testing on an HP LaserJet 1200 printer.
You said it was a
dot matrix printer!!! Big difference!
> Is it possible that these other things can't be changed for
> this type of printer?
I know that you can accomplish what you want. I just don't
know for sure how to do it.
~ JD