Language Monitor OpenPortEx fails when calling Port Monitor's Open

Language Monitor OpenPortEx fails when calling Port Monitor's Open

Post by Q2hyaXMgU » Sat, 18 Jul 2009 00:55:02


I am writing a custom language monitor following the DDK PJLMon.dll example,
but it is failing during OpenPortEx().

During my OpenPortEx implementation I get an error when calling the port
monitor's OpenPort function:

...
...
int ret = 0;

if(pMonitor->cbSize == sizeof(MONITOREX))
{
MONITOREX FAR * pMon = (MONITOREX FAR *)pMonitor;
ret = (*pMon->Monitor.pfnOpenPort)(pPortName, &hPort);
}
...
...

The error message I get is "0xc0000005 access violation", and happens on
both LPT1 and USB001 ports (the printer is actually a usb printer, but I
tested LPT1 in the Add Printer wizard just to see what would happen).

In the de *** , I can view the port monitor structure and see that
pfnOpenPort has a non-zero handle value (75bb690e), but debug doesn't show a
method name for it (whereas some of the other pfn's such as pfnClosePort show
a method name next to the address value, such as "DynaPort_ClosePort"). This
non-zero value is also in contrast to several of the pfn's that have zero
(null) values. If the pfnOpenPort has an address value, then I'm not sure
why I can't call it or why debug can't figure out what the function name is
while it can for others.

[From DDK documentation:]
Usbprint.sys, together with USBMON, provides an interface very similar to
that used by parallel printers. In many cases, it is possible for a single
printer driver or language monitor to work correctly on both parallel and USB
printers without modification. If a language monitor uses only the WritePort
and ReadPort functions and the IOCTL_PAR_QUERY_DEVICE_ID request, it will be
portable between USB and parallel printers.
....

This seems to knock out most of pjlmon's code, so I'm curious if there is
something I'm missing or if pjlmon was never intended to work with USB ports.
I've seen posts from "experts" that say pjlmon is compatible with any port,
so maybe there's something I'm missing...

My main reason for writing a custom language monitor is to enable bidi
communication so I can monitor ink levels, job status, paper trays, etc. It
seems from the DDK docs that the language monitor should implement calls
using IOCTL routines.

If anyone has some pointers, or maybe a sample on how to implement a
USB-compatible language monitor, it would be greatly appreciated!

Thanks

--
-Chris
 
 
 

Language Monitor OpenPortEx fails when calling Port Monitor's Open

Post by Q2hyaXMgU » Wed, 22 Jul 2009 01:27:01

I am writing a custom language monitor following the DDK PJLMon.dll example,
but it is failing during OpenPortEx().

During my OpenPortEx implementation I get an error when calling the port
monitor's OpenPort function:

BOOL WINAPI ADXOpenPortEx(HANDLE hLangMon, HANDLE hPortMon, LPWSTR
pPortName, LPWSTR pPrinterName, LPHANDLE phPort, LPMONITOR2 pPortMonFx)
{
...
int x = (*pPortMonFx->pfnOpenPort)(hLangMon, pPortName, phPort);
...
}

The error message I get is "0xc0000005 access violation", and happens on
both LPT1 and USB001 ports (the printer is actually a usb printer, but I
tested LPT1 in the Add Printer wizard just to see what would happen).

In the de *** , I can view the port monitor structure (pPortMonFx in my
code) and see that pfnOpenPort has a non-zero handle value (75bb690e), but
debug doesn't show a method name for it (whereas some of the other pfn's such
as pfnClosePort show a method name and parameter signature next to the
address value, such as "DynaPort_ClosePort"). This non-zero value for
pfnOpenPort is also in contrast to several of the pfn's that have zero (null)
values, which is what I expected for those that are not implemented by the
port monitor. If the pfnOpenPort has an address value, then I'm not sure why
I can't call it or why debug can't figure out what the function name is while
it can for others.

[From DDK documentation:]
Usbprint.sys, together with USBMON, provides an interface very similar to
that used by parallel printers. In many cases, it is possible for a single
printer driver or language monitor to work correctly on both parallel and USB
printers without modification. If a language monitor uses only the WritePort
and ReadPort functions and the IOCTL_PAR_QUERY_DEVICE_ID request, it will be
portable between USB and parallel printers.
....

This seems to knock out most of pjlmon's code, so I'm curious if there is
something I'm missing or if pjlmon was never intended to work with USB ports.
I've seen posts from "experts" that say pjlmon is compatible with any port,
so maybe there's something I'm missing...

My main reason for writing a custom language monitor is to enable bidi
communication so I can monitor ink levels, job status, paper trays, etc. It
seems from the DDK docs that the language monitor should implement calls
using IOCTL routines.

I have WinXP sp3 installed, and have usbmon.dll dated 3/6/2007. I also
tried an older version of usbmon.dll (2/27/2006), but even though the
"DynaMon" pfn's changed (such as pfnClosePort), the pfnOpenPort still pointed
to the same address and still didn't work.

I'm not sure if there is something wrong with my code, or with my Windows
config, or something else. As far as I can tell my code is being called
properly, but it seems the MONITOR2 being passed in from the spooler has a
bad address for pfnOpenPort.

Thanks for any help,
-Chris