We are attempting to call GetPrinterDataEx() for a printer to obtain data
from the registry in its Language Monitor's OpenPortEx() call. This worked
fine up until Windows XP Service Pack 2, where we now find that the call
hangs indefinitely inside I_RpcSendReceive().

Is this a known issue, and if so what are the suggested workarounds given
that we: -
1) Have a bidirectional printer and so wish to create a connection to it in
OpenPortEx() rather than in StartDocPort() (i.e. before a job need be printed
to it)
2) Need information from the registry to establish the connection.

Joe Hindmarsh

RE: Calling GetPrinterDataEx from OpenPortEx in Language Monitor in XP by dsarma

dsarma
Tue Mar 22 16:23:28 CST 2005

------=_NextPart_0001_87255EF0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

We have not seen this behavior with XP Service Pack 2.

You may want to uninstall the driver completely. Delete the driver fro the
Printers and
Faxes folder. Then right click on the folder anf go to Server Properties.
From there select the
Drivers tab. Select the name of the driver and clcik the Remove button.
Then follow the article
below to remove the Language Monitor. You may use regedit.exe.

http://support.microsoft.com/default.aspx?scid=kb;en-us;155516
How to Remove the Lexmark MarkVision Monitor

Reinstall the driver again and see if the problem goes away.

Deba Sarma
MICROSOFT DDK Print Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

------=_NextPart_0001_87255EF0
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 We have not seen this behavior with XP Service Pack 2.
\par
\par You may want to uninstall the driver completely. Delete the driver fro the Printers and
\par Faxes folder. Then right click on the folder anf go to Server Properties. From there select the
\par Drivers tab. Select the name of the driver and clcik the Remove button. Then follow the article
\par below to remove the Language Monitor. You may use regedit.exe.
\par
\par http://support.microsoft.com/default.aspx?scid=kb;en-us;155516
\par How to Remove the Lexmark MarkVision Monitor
\par
\par Reinstall the driver again and see if the problem goes away.
\par
\par Deba Sarma
\par MICROSOFT DDK Print Developer Support
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par }
------=_NextPart_0001_87255EF0--


RE: Calling GetPrinterDataEx from OpenPortEx in Language Monitor i by Joe

Joe
Wed Mar 23 00:45:01 CST 2005

"Debabrata Sarma[MSFT]" wrote:

> We have not seen this behavior with XP Service Pack 2.
>
Okay, steps to reproduce: -

1) Either insert the following lines at the start of a langaunge monitor's
OpenPortEx call:

DWORD size;
HANDLE hPrinter;
PRINTER_DEFAULTS PrinterDef = { NULL, NULL, PRINTER_ALL_ACCESS };
OpenPrinter(pszPrinterName, &hPrinter, &PrinterDef);
GetPrinterDataExW(hPrinter, L"PrinterDriverData", L"test", 0, 0, 0,
&size);
ClosePrinter(hPrinter);

And build and install a debug version of the driver.

OR

At the end of the post is a bunch of files defining a minimal languange
monitor. Create these files in a single directory. Run the Windows Server
2003 DDK build utility for checked builds in this directory. This will create
a file mypjlmon.dll. Copy this file to your windows\system32 directory. Then
in regedit go to
HKLM\System\CurrentControlSet\Control\Print\Environments\Windows NT
x86\Drivers and find a driver that has a non-empty "Monitor" field". Then go
to HKLM\System\CurrentControlSet\Control\Print\Monitors and find this monitor
and change its "Driver" entry to be mypjlmon.dll.

2) Restart the spooler.

3) Attach a debugger to it.

4) Breakpoint on the GetPrinterDataExW() line above.

5) Load a printer dialog to force OpenPortEx() to be called.

6) When the breakpoint happens step over the line.

Now observe. On XP Sp1 and prior the call will fail straight away
immediately due to their being no such key defined. On XP Sp2 you will get
stuck in an infinite recursive loop with this breakpoint being called each
time, until stack overflow occurs (this is actually slightly different
behaviour to what I originally described - when I used VC7.1 as the compiler
it just locked up rather than infinite looping).

Files for step 1 follow.

Joe Hindmarsh

-----------------------------------------------------------
File: makefile

!INCLUDE $(NTMAKEENV)\makefile.def
-----------------------------------------------------------
File: mypjlmon.def

LIBRARY MYPJLMON

EXPORTS
InitializePrintMonitor2
-----------------------------------------------------------
File: mypjlmon.prf

-----------------------------------------------------------
File: sources

NTPROFILEINPUT=yes

C_DEFINES=-DUNICODE -DNO_STRICT


!IFNDEF MSC_WARNING_LEVEL
MSC_WARNING_LEVEL=/W3
!ENDIF
MSC_WARNING_LEVEL=$(MSC_WARNING_LEVEL) /WX

TARGETNAME=mypjlmon
TARGETPATH=obj
TARGETTYPE=DYNLINK
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib \
$(SDK_LIB_PATH)\advapi32.lib \
$(SDK_LIB_PATH)\user32.lib \
$(SDK_LIB_PATH)\spoolss.lib

DLLENTRY=_DllMainCRTStartup

USE_MSVCRT=1
SOURCES=pjlmon.c \
pjlmon.rc
----------------------------------------------------------
File: pjlmon.rc

#include <windows.h>
#define VER_FILETYPE VFT_DLL
#define VER_FILESUBTYPE VFT2_UNKNOWN
#define VER_FILEDESCRIPTION_STR "PJL Language monitor"
#define VER_INTERNALNAME_STR "MYPJLMON.DLL"
#define VER_ORIGINALFILENAME_STR "MYPJLMON.DLL"

----------------------------------------------------------
File: pjlmon.c

#include <windows.h>
#include <winspool.h>
#include <winddi.h>
#include <winsplp.h>

BOOL DllMain(
IN HANDLE hModule,
IN DWORD dwReason,
IN LPVOID lpRes)
{
UNREFERENCED_PARAMETER(lpRes);

switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
break;
default:
;
}

return TRUE;
}

BOOL WINAPI PJLMonOpenPortEx(
IN HANDLE hMonitor,
IN HANDLE hMonitorForPort,
IN LPTSTR pszPortName,
IN LPTSTR pszPrinterName,
IN OUT LPHANDLE pHandle,
IN OUT MONITOR2 *pMonitor)
{
DWORD size;
HANDLE hPrinter;
PRINTER_DEFAULTS PrinterDef = { NULL, NULL, PRINTER_ALL_ACCESS };
OpenPrinter(pszPrinterName, &hPrinter, &PrinterDef);
GetPrinterDataExW(hPrinter, L"PrinterDriverData", L"test", 0, 0, 0,
&size);
ClosePrinter(hPrinter);

return TRUE;
}

BOOL WINAPI PJLMonStartDocPort(
IN HANDLE hPort,
IN LPTSTR pszPrinterName,
IN DWORD dwJobId,
IN DWORD dwLevel,
IN LPBYTE pDocInfo)
{
return TRUE;
}

BOOL WINAPI PJLMonReadPort(
IN HANDLE hPort,
OUT LPBYTE pBuffer,
IN DWORD cbBuf,
OUT LPDWORD pcbRead)
{
return FALSE;
}

BOOL WINAPI PJLMonWritePort(
IN HANDLE hPort,
IN LPBYTE pBuffer,
IN DWORD cbBuf,
IN LPDWORD pcbWritten)
{
return FALSE;
}

BOOL WINAPI PJLMonEndDocPort(
HANDLE hPort)
{
return TRUE;
}

BOOL WINAPI PJLMonClosePort( HANDLE hPort)
{
return FALSE;
}

BOOL WINAPI PJLMonGetPrinterDataFromPort(
HANDLE hPort,
DWORD ControlID,
LPTSTR pValueName,
LPTSTR lpInBuffer,
DWORD cbInBuffer,
LPTSTR lpOutBuffer,
DWORD cbOutBuffer,
LPDWORD lpcbReturned)
{
return FALSE;
}

void WINAPI PJLMonShutdown(
HANDLE hMonitor)
{
}

MONITOR2 gMonitor2 =
{
sizeof(MONITOR2),
NULL, // EnumPort not supported
NULL, // OpenPort not supported
PJLMonOpenPortEx,
PJLMonStartDocPort,
PJLMonWritePort,
PJLMonReadPort,
PJLMonEndDocPort,
PJLMonClosePort,
NULL, // AddPort not supported
NULL, // AddPortEx not supported
NULL, // ConfigurePort not supported
NULL, // DeletePort not supported
PJLMonGetPrinterDataFromPort,
NULL, // SetPortTimeOuts not supported
0,
0,
0,
PJLMonShutdown,
NULL, // SendRecvBidiDataFromPort not supported
};

LPMONITOR2 WINAPI InitializePrintMonitor2(
PMONITORINIT pMonitorInit,
PHANDLE phMonitor
)
{
return &gMonitor2;
}


RE: Calling GetPrinterDataEx from OpenPortEx in Language Monitor i by dsarma

dsarma
Thu Mar 24 11:57:43 CST 2005

------=_NextPart_0001_8B53C1AD
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Thanks for providing the reproducible steps.
We will investigate the issue.


Deba Sarma
MICROSOFT DDK Print Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

------=_NextPart_0001_8B53C1AD
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 Thanks for providing the reproducible steps.
\par We will investigate the issue.
\par
\par
\par Deba Sarma
\par MICROSOFT DDK Print Developer Support
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par }
------=_NextPart_0001_8B53C1AD--


RE: Calling GetPrinterDataEx from OpenPortEx in Language Monitor i by dsarma

dsarma
Mon Apr 04 17:33:28 CDT 2005

------=_NextPart_0001_CA2114C8
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This is to let you know that we have reproduced the symptom.

We are now looking at the code changes we made in SP2 which could have
introduced this
problem.

We will let you know once we get more information.

Thanks.

Best regards.

Deba Sarma
MICROSOFT DDK Print Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

------=_NextPart_0001_CA2114C8
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 This is to let you know that we have reproduced the symptom.
\par
\par We are now looking at the code changes we made in SP2 which could have introduced this
\par problem.
\par
\par We will let you know once we get more information.
\par
\par Thanks.
\par
\par Best regards.
\par
\par Deba Sarma
\par MICROSOFT DDK Print Developer Support
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par }
------=_NextPart_0001_CA2114C8--


RE: Calling GetPrinterDataEx from OpenPortEx in Language Monitor i by dsarma

dsarma
Tue Apr 05 15:40:20 CDT 2005

------=_NextPart_0001_CEDFE035
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

The code change was made for some other design related reasons.

Will it work for you to use EnumPrinterData to get the information you want
or use
GetPrinterDataFromPort?

You can send me email directly to the address dsarma@microsoft.com for
offline communication.


Deba Sarma
MICROSOFT DDK Print Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

------=_NextPart_0001_CEDFE035
Content-Type: text/x-rtf
Content-Transfer-Encoding: 7bit

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 The code change was made for some other design related reasons.
\par
\par Will it work for you to use EnumPrinterData to get the information you want or use
\par GetPrinterDataFromPort?
\par
\par You can send me email directly to the address dsarma@microsoft.com for
\par offline communication.
\par
\par
\par Deba Sarma
\par MICROSOFT DDK Print Developer Support
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par }
------=_NextPart_0001_CEDFE035--