Discussion:
InitializePrintMonitor2 in Language monitor
(too old to reply)
DDKUser
2009-07-08 19:58:01 UTC
Permalink
Hi,

We have a custom language monitor that we have been using for our printer.
It uses the old Monitor structure. We would like to use the Monitor2
structure and InitializePrintMonitor2. However when we install the driver the
spooler crashes when it tries to invoke OpenportEx() function for the
underlying port monitor from the language monitor's MyMonOpenportEx()
function. The crash occurs right between the first and the 2nd DbgPrint
statements in the MyMonOpenportEx() function. Some code snippets follow.

-------------------

MONITOR2 Monitor2 = {
sizeof(MONITOR2),
NULL,
NULL,
MyMonOpenPortEx,
MyMonStartDocPort,
MyMonWritePort,
MyMonReadPort,
MyMonEndDocPort,
MyMonClosePort,
NULL, /* AddPort */
NULL, /* AddPortEx */
NULL, /* ConfigurePort */
NULL, /* DeletePort */
MyMonGetPrinterDataFromPort, /* GetPrinterDataFromPort */
NULL,
NULL,
NULL,
NULL,
MyMonShutdown,
MyMonSendRecvBidiDataFromPort
};

LPMONITOR2
WINAPI
InitializePrintMonitor2(
IN PMONITORINIT pMonitorInit,
IN PHANDLE phMonitor)

{
if ( Is_Win2000( ) )
Monitor2.cbSize = MONITOR2_SIZE_WIN2K;

*phMonitor = (PHANDLE)pMonitorInit;
return &Monitor2;
}


BOOL
WINAPI
MyMonOpenPortEx(IN HANDLE hMonitor, //MONITOR2 only
IN HANDLE hMonitorPort,
IN LPTSTR pszPortName,
IN LPTSTR pszPrinterName,
IN OUT LPHANDLE pHandle,
IN OUT LPMONITOR2 pMonitor
)

{
PINIPORT pIniPort;
BOOL bRet = FALSE;
BOOL bInSem = FALSE;

//
// Validate port monitor
//
if ( !pMonitor ||
!pMonitor->pfnOpenPort ||
!pMonitor->pfnStartDocPort ||
!pMonitor->pfnWritePort ||
!pMonitor->pfnReadPort ||
!pMonitor->pfnClosePort )
{


SetLastError(ERROR_INVALID_PRINT_MONITOR);
goto Cleanup;
}

EnterSplSem();
bInSem = TRUE;

//
// Is the port open already?
//
if ( pIniPort = FindIniPort(pszPortName) ) {

SetLastError(ERROR_BUSY);
goto Cleanup;
}
pIniPort = CreatePortEntry(pszPortName);
LeaveSplSem();
bInSem = FALSE;

DbgPrint(1, "LangMon(%s):: MyMonOpenPortEx Before Port Monitor Open",
pszPrinterName);
if ( pIniPort &&
(*pMonitor->pfnOpenPort)(hMonitor, pszPortName, &pIniPort->hPort) )
{

DbgPrint(1, "LangMon(%s):: Port Monitor open Done", pszPrinterName);
*pHandle = pIniPort;
CopyMemory((LPBYTE)&pIniPort->fn, (LPBYTE)pMonitor,
sizeof(*pMonitor));

//Initialize Vars.
memset(pIniPort->statusBytes, 0, 50);
pIniPort->pszSavedPrnName = AllocSplStr(pszPrinterName);
pIniPort->bPSBAvailable = FALSE;
pIniPort->nStatusCnt = 0;
pIniPort->status &= ~PP_INSTARTDOC;
pIniPort->PrinterStatus = 0;
CreateUstatusThread(pIniPort);
bRet = TRUE;
}
else
{

bRet = FALSE;
}

Cleanup:
if ( bInSem ) {

LeaveSplSem();
}
SplOutSem();
return bRet;
}


---------------------

The language monitor worked fine with the older
Monitor/InitializePrintMonitor implementation. Any ideas/suggestions on what
we are not doing right here, would be greatly appreciated.

Thanks.
---
DDKUser
d***@resplendence.com
2009-07-09 16:02:51 UTC
Permalink
When you initialize the MONITOR2 structure you initialize the pfnOpenPort
function to NULL. If this is NULL it's not clear how this passed your
sanity check (if (...!pMonitor->pfnOpenPort)) however if it is not NULL you
should be able to step through your pfnOpenPort routine and see what this
does. Otherwise it's suggested you paste the debugger output of
!analyze -v

//Daniel
Post by DDKUser
MONITOR2 Monitor2 = {
sizeof(MONITOR2),
NULL,
NULL,
MyMonOpenPortEx,
.....
Post by DDKUser
//
// Validate port monitor
//
if ( !pMonitor ||
!pMonitor->pfnOpenPort ||
!pMonitor->pfnStartDocPort ||
....
......
Post by DDKUser
(*pMonitor->pfnOpenPort)(hMonitor, pszPortName,
&pIniPort->hPort) )
Loading...