I am interested in being able to call DrvEnablePDEV
for an arbitrary printer so I can examine the device information. To do this I need (on top of a lot of other things) the HDEV
which is described in the documentation as
GDI-supplied handle to the device. This handle must be used as input to some GDI callbacks, such as EngGetDriverName.
Is it possible for me to obtain this handle used by the engine somehow? Or could I substitute it for some other handle? (although I'm guessing that would be risky at best)
It turns out there's a good way to fake out the DLLs for the print driver. There are values in the registry under the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments
that point to the binary names. By copying my own driver into the print driver v3 directory and mocking the names in the registry I can get the functions and all their arguments as they come through and corresponding to the right driver. So then I can just call CreateDC
or something on the print driver to get access to the driver's entry points.
Restarting the print spooler service is necessary for the registry changes to take effect.
Thanks to Harry Johnston for the idea of hooking the driver DLL, which got me on a good track.