
Using RedMon environment variables to get original Document Name
The following snippet of code for Redmon can retrieve the document
name (or something hopefully relevant).
CString GetJobDocument( void )
{
DWORD dwJob = atoi( getenv("REDMON_JOB") );
HANDLE hPrinter = NULL;
PRINTER_DEFAULTS *pd = NULL;
pd = (PRINTER_DEFAULTS*)GlobalAlloc(GPTR, sizeof(PRINTER_DEFAULTS) );
ZeroMemory( pd, sizeof(PRINTER_DEFAULTS));
pd->DesiredAccess = PRINTER_ACCESS_USE;
pd->pDatatype = NULL;
pd->pDevMode = NULL;
if( !OpenPrinter( getenv("REDMON_PRINTER"), &hPrinter, pd ) )
{
return "";
}
// Second, GetJob
DWORD dwNeeded = 0;
GetJob(hPrinter, dwJob, 1, NULL, 0, &dwNeeded);
JOB_INFO_1 *ji = (JOB_INFO_1*)GlobalAlloc(GPTR, dwNeeded + 1 );
ZeroMemory( ji, dwNeeded + 1);
GetJob(hPrinter, dwJob, 1, (LPBYTE)ji, dwNeeded, &dwNeeded);
CString csToReturn = ji->pDocument;
return csToReturn;
Quote:
}
This should do the trick.