Exemplo n.º 1
0
JNIEXPORT jintArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaIDs
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jintArray result = NULL;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        int numPapersFirst = DeviceCapabilities(name, info->pPortName, DC_PAPERS, NULL, NULL);
        if (numPapersFirst > 0) {
            WORD *ids = new WORD[numPapersFirst];
            int numPapers = DeviceCapabilities(name, info->pPortName, DC_PAPERS, (LPSTR)ids, NULL);
            if (numPapers == numPapersFirst) {
                result = env->NewIntArray(numPapers);
                int *intIDs = new int[numPapers];
                for (int i = 0; i < numPapers; i++) {
                    intIDs[i] = (int)ids[i];
                }
                env->SetIntArrayRegion(result, 0, numPapers, (jint *)intIDs);
                delete[] intIDs;
            }
            delete[] ids;
        }
        free(info);
    }
    return result;
}
Exemplo n.º 2
0
JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getPrinterIsAcceptingJobs
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jint result = -1;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        if (info->Status & (PRINTER_STATUS_ERROR |
                            PRINTER_STATUS_NO_TONER |
                            PRINTER_STATUS_NOT_AVAILABLE |
                            PRINTER_STATUS_OFFLINE |
                            PRINTER_STATUS_OUT_OF_MEMORY |
                            PRINTER_STATUS_OUTPUT_BIN_FULL |
                            PRINTER_STATUS_PAPER_JAM |
                            PRINTER_STATUS_PAGE_PUNT |
                            PRINTER_STATUS_PAPER_OUT |
                            PRINTER_STATUS_PAPER_PROBLEM |
                            PRINTER_STATUS_PAUSED |
                            PRINTER_STATUS_PENDING_DELETION |
                            PRINTER_STATUS_USER_INTERVENTION)) {
            result = 0;
        } else {
            result = 1;
        }
        free(info);
    }
    return result;
}
Exemplo n.º 3
0
cngplpData* cngplpNew(char *file_name)
{
	cngplpData *data = NULL;

	if((data = (cngplpData *)malloc(sizeof(cngplpData))) == NULL)
		return NULL;
	memset(data, 0 , sizeof(cngplpData));

	if(GetPrinterInfo(data) < 0){
		MemFree(data);
		return NULL;
	}

	if(cngplpInitOptions(data) < 0){
		MemFree(data);
		return NULL;
	}

	if(file_name){
		int num = strlen(file_name);
		data->file_name = (char *)malloc(num + 1);
		memset(data->file_name, 0, num + 1);
		strncpy(data->file_name, file_name, num);
	}

	return data;
}
Exemplo n.º 4
0
JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaNames
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jobjectArray result = NULL;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        int numNamesFirst = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, NULL, NULL);
        if (numNamesFirst > 0) {
            char *buffer = new char[65 * numNamesFirst];
            int numNames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, (LPSTR)buffer, NULL);
            if (numNames == numNamesFirst) {
                jclass jstring_class = env->FindClass("java/lang/String");
                result = env->NewObjectArray(numNames, jstring_class, jstring());
                for (int i = 0; i < numNames; i++) {
                    char *name = buffer + i*64;
                    jstring jname = env->NewStringUTF(name); 
                    env->SetObjectArrayElement(result, i, jname);
                    env->DeleteLocalRef(jname);
                }
            }
            delete[] buffer;
        }
        free(info);
    }
    return result;
}
Exemplo n.º 5
0
JNIEXPORT jintArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getResolutionsSupported
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jintArray resolutions = NULL;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        int count = DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, NULL, NULL);
        if (count > 0) {
            LONG *nativeArray = new LONG[count * 2];
            resolutions = env->NewIntArray(count * 2);
            if (DeviceCapabilities(name, info->pPortName, DC_ENUMRESOLUTIONS, (LPSTR)nativeArray, NULL) > 0) {
                jint *intArray = new jint[count * 2];
                for (int i = 0; i < count * 2; i++) {
                    intArray[i] = (jint)((int)nativeArray[i]);
                }
                env->SetIntArrayRegion(resolutions, 0, count * 2, intArray);     
                delete[] intArray;
            }
            delete[] nativeArray;
        }
        free(info);
    }
    return resolutions;
}
Exemplo n.º 6
0
cngplpData* cngplpNew(char *file_name, const char *ppdFilePath)
#endif
{
	cngplpData *data = NULL;

	if((data = (cngplpData *)malloc(sizeof(cngplpData))) == NULL)
		return NULL;
	memset(data, 0 , sizeof(cngplpData));

#ifndef _OPAL
	if(GetPrinterInfo(data) < 0)
#else
	if(GetPrinterInfo_iOS(data, ppdFilePath) < 0)
#endif
	{
		MemFree(data);
		return NULL;
	}

	if(cngplpInitOptions(data) < 0){
		MemFree(data);
		return NULL;
	}

	if(file_name){
		int num = strlen(file_name);
		data->file_name = (char *)malloc(num + 1);
		memset(data->file_name, 0, num + 1);
		strncpy(data->file_name, file_name, num);
	}

	return data;
}
Exemplo n.º 7
0
JNIEXPORT jobjectArray JNICALL Java_org_apache_harmony_x_print_GDIClient_getMediaSizesSupported
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jobjectArray result = NULL;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        int numSizes = DeviceCapabilities(name, info->pPortName, DC_PAPERSIZE, NULL, NULL);
        if (numSizes > 0) {
            POINT *sizes = new POINT[numSizes];
            int numSizes = DeviceCapabilities(name, info->pPortName, DC_PAPERSIZE, (LPSTR)sizes, NULL);
            if (numSizes > 0) {
                jclass IntArrayClass = env->FindClass("[I");
                result = env->NewObjectArray(numSizes, IntArrayClass, NULL);
                for (int i = 0; i < numSizes; i++) {
                    jintArray size = env->NewIntArray(2);
                    int *nativeArray = new int[2];
                    nativeArray[0] = sizes[i].x;
                    nativeArray[1] = sizes[i].y;
                    env->SetIntArrayRegion(size, 0, 2, (jint *)nativeArray);
                    env->SetObjectArrayElement(result, i, size);
                }
            }
        }

#ifdef PRINTING_DEBUG
        int count = DeviceCapabilities(name, info->pPortName, DC_PAPERS, NULL, NULL);
        if( count > 0 ) {
            printf("\n\n");
            WORD *papers = new WORD[count];
            count = DeviceCapabilities(name, info->pPortName, DC_PAPERS, (LPSTR)papers, NULL);
            printf("Found %d paper types.\n", count);
            for (int i = 0; i < count; i++) {
                printf("%d: %d\n", i+1, papers[i]);
            }
            delete [] papers;
        }
        
        int cnames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, NULL, NULL);
        if( cnames > 0 ) {
            printf("\n\n");
            char (*papernames)[64] = new char[cnames][64];
            cnames = DeviceCapabilities(name, info->pPortName, DC_PAPERNAMES, (LPSTR)papernames, NULL);
            printf("Found %d paper names.\n", cnames);
            for (int i = 0; i < cnames; i++) {
                printf("%d: %s\n", i+1, papernames[i]);
            }
            delete [] papernames;
        }
#endif /* PRINTING_DEBUG */
        free(info);
    }
    return result;
}
Exemplo n.º 8
0
JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getCopiesSupported
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jint result = 0;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        result = DeviceCapabilities(name, info->pPortName, DC_COPIES, NULL, NULL);
        free(info);
    }
    return result;
}
Exemplo n.º 9
0
JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getQueuedJobCount
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jint result = -1;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        result = info->cJobs;
        free(info);
    }
    return result;
}
Exemplo n.º 10
0
JNIEXPORT jint JNICALL Java_org_apache_harmony_x_print_GDIClient_getPagesPerMinuteColor
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jint result = 0;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        info->pDevMode->dmColor = DMCOLOR_COLOR;
        result = DeviceCapabilities(name, info->pPortName, DC_PRINTRATEPPM, NULL, info->pDevMode);
        free(info);
    }
    return result;
}
Exemplo n.º 11
0
JNIEXPORT jstring JNICALL Java_org_apache_harmony_x_print_GDIClient_getPrinterLocation
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jstring result = NULL;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        if (info->pLocation != NULL && strcmp(info->pLocation, "") != 0) {
            result = env->NewStringUTF(info->pLocation);
        }
        free(info);
    }
    return result;
}
Exemplo n.º 12
0
JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getCollateSupported
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jboolean result = JNI_FALSE;

    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        if (DeviceCapabilities(name, info->pPortName, DC_COLLATE, NULL, NULL) == 1) {
            result = JNI_TRUE;
        }
        free(info);
    }
    return result;
}
Exemplo n.º 13
0
JNIEXPORT jboolean JNICALL Java_org_apache_harmony_x_print_GDIClient_getOrientationSupported
(JNIEnv *env, jclass owner, jstring printerName) {
    const char *name = env->GetStringUTFChars(printerName, 0);
    jboolean result = JNI_FALSE;
    
    PRINTER_INFO_2 *info = GetPrinterInfo(name);
    if (info != NULL) {
        int orientation = DeviceCapabilities(name, info->pPortName, DC_ORIENTATION, NULL, NULL);
        if (orientation == 0 || orientation == 90 || orientation == 270) {
            result = JNI_TRUE;
        }
        free(info);
    }
    return result;
}
Exemplo n.º 14
0
int GetAllPrinters()
{
	cups_dest_t *all_dests = NULL;
	cups_dest_t *curr_dest = NULL;
	PrintersInfo *printers = NULL;
	int num = 0, i = 0;
	PrinterInfo *info = NULL;

	num = cupsGetDests(&all_dests);
	if(0 == num){
		return -1;
	}
	printers = (PrintersInfo*)malloc(sizeof(PrintersInfo));
	if(NULL == printers){
		return -1;
	}
	memset(printers, 0, sizeof(PrintersInfo));
	g_printers = printers;

	curr_dest = all_dests;
	for(i = 0; i < num; i++){
		if(curr_dest->name != NULL){
			info = GetPrinterInfo((char*)curr_dest->name);
			if(info != NULL){
				printers->printer_list = g_list_append(printers->printer_list, info);
				if(TRUE == curr_dest->is_default){
					printers->curr_printer = info;
				}
			}
		}
		curr_dest++;
	}
	if(0 == g_list_length(printers->printer_list))
	{
		return -1;
	}
	if(NULL == printers->curr_printer){
		printers->curr_printer = g_list_nth_data(printers->printer_list, 0);
	}
	cupsFreeDests(num, all_dests);
	return 0;
}
Exemplo n.º 15
0
VOID _cdecl Main( WORD NumArgs, CHAR *Args[], CHAR *EnvStrings[] )
    {
    MSG     Msg;
    WORD    Key;

    CHAR FileName[65];
    CHAR PrinterPort[65];

    HFILE TMSBegrFile;
    HFILE TMSAbtFile;
    HFILE TMSZKontFile;

    DWORD EffTime;

    WinInitialize( MAXNUMWINDOWS );
    WinCreateWindow( Desktop, &Desktop, NULL, 0, 0, 0, 0, 0, 0 );

    WinHideCursor();
    WinColor( Desktop, NORMAL, 0, 0, WinGetx2( Desktop ), WinGety2( Desktop ) );

    WinCreateWindow( Desktop, &Bottomline, BottomlineProc, 0, 0, BOTTOMLINEX1, BOTTOMLINEY1, BOTTOMLINEX2, BOTTOMLINEY2 );

    if( !ReadConfigData() )
	{
	static struct HelpKey HelpKeys[NUMLAUFWERKHELPKEYS] =
	    { {	0,   0, "</>    Wert erh�hen/erniedrigen" },
	      { 0,   1, "<Enter>  Wert akzeptieren" },
	      { 40,  1, "<Esc>    Programm verlassen" } };

	HWND TMSLaufwerk;
	BOOL LaufwerkOK;

	WinFill( Desktop, '�',	0, 22, 79, 22 );
	InitConfigData();

	WinString( Desktop, "TMS Laufwerk", CENTER, 0, 7 );
	WinString( Desktop, "������������", CENTER, 0, 8 );
	WinColor( Desktop, HIGHLIGHT, 33, 7, 46, 7 );
	WinCreateWindow( Desktop, &TMSLaufwerk, TMSLaufWerkProc, 0, 0, 37, 10, 40, 10 );
	WinString( Desktop, "Geben Sie bitte an, in welchem Laufwerk sich TMS befindet.", CENTER, 0, 14 );

	WinSendMsg( Bottomline, WM_HELP, (WORD)&HelpKeys, NUMLAUFWERKHELPKEYS );

	WinSendMsg( TMSLaufwerk, WM_SHOW, 0, 0 );
	WinSendMsg( TMSLaufwerk, WM_SETFOCUS, 0, 0 );

	do
	    {
	    LaufwerkOK = TRUE;
	    do
		{
		Key = BiosGetKey();
		Msg = WinSendMsg( TMSLaufwerk, WM_CHAR, (MPARAM)Key, 0 );
		}
	    while( (WORD)Msg != KBENTER && (WORD)Msg != KBESC );

	    if( (WORD)Msg == KBESC )
		{
		DosFreeFarMem( ConfigData );

		WinDestroyWindow( TMSLaufwerk );
		WinDestroyWindow( Bottomline );
		WinDestroyWindow( Desktop );
		return;
		}

	    if( !OpenPathFile() )
		{
		LaufwerkOK = FALSE;
		}
	    }
	while( !LaufwerkOK );

	ClosePathFile();
	WinDestroyWindow( TMSLaufwerk );
	WinColor( Desktop, NORMAL, 0, 0, WinGetx2( Desktop ), 21 );
	WinFill( Desktop, SPACECHAR, 0, 0, WinGetx2( Desktop ), WinGety2( Desktop ) );
	}

    switch( NumArgs )
	{
	case 2:
	    StdStrLwr( Args[1] );
	    if( StdStrCmp( Args[1], "exportfile" ) == 0 ||
		StdStrCmp( Args[1], "export" ) == 0 )
		{
		WinFill( Desktop, '�',	0, 22, 79, 22 );
		ExportFileConversion();
		}
	    else
		{
		; // Debug!!!!
		}
	    break;

	case 1:
	    if( !OpenPathFile() )
		; // Debug!!!!!

	    ReadPathFileEntry( TMSBEGRUENDNO, FileName, FALSE );

	    DosOpen( FileName, &TMSBegrFile, OPEN_RDONLY );
	    DosLastModTime( TMSBegrFile, &EffTime );
	    if( ConfigData->TMSBegruendungsDatum != EffTime )
		{
		if( !CreateList( TMSBegrFile, BEGRUENDUNGEN ) )
		    {
		    WinString( Desktop, "In TMS sind 0 Begr�ndungen verzeichnet!", LEFT, 0, 0 );
		    return; // Debug-Version!!!!!
		    }

		SortList( BEGRUENDUNGEN );
		ConfigData->TMSBegruendungsDatum = EffTime;
		StdFarMemSet( ConfigData->BegrCheckListe, TRUE, sizeof( ConfigData->BegrCheckListe ) );
		}
	    DosClose( TMSBegrFile );

	    ReadPathFileEntry( TMSABTEILNO, FileName, FALSE );

	    DosOpen( FileName, &TMSAbtFile, OPEN_RDONLY );
	    DosLastModTime( TMSAbtFile, &EffTime );
	    if( ConfigData->TMSAbteilungsDatum != EffTime )
		{
		if( !CreateList( TMSAbtFile, ABTEILUNGEN ) )
		    {
		    WinString( Desktop, "In TMS sind 0 Abteilungen verzeichnet!", LEFT, 0, 0 );
		    return; // Debug-Version!!!!!
		    }
		SortList( ABTEILUNGEN );
		ConfigData->TMSAbteilungsDatum = EffTime;
		StdFarMemSet( ConfigData->AbtCheckListe, TRUE, sizeof( ConfigData->AbtCheckListe ) );
		}
	    DosClose( TMSAbtFile );

	    ReadPathFileEntry( TMSZEITKNO, FileName, FALSE );

	    DosOpen( FileName, &TMSZKontFile, OPEN_RDONLY );
	    DosLastModTime( TMSZKontFile, &EffTime );
	    if( ConfigData->TMSZeitKontiDatum != EffTime )
		{
		if( !CreateList( TMSZKontFile, ZEITKONTI ) )
		    {
		    WinString( Desktop, "In TMS sind 0 Zeitkonti verzeichnet!", LEFT, 0, 0 );
		    return; // Debug-Version!!!!!
		    }
		// SortList( ZEITKONTI );
		ConfigData->TMSZeitKontiDatum = EffTime;
		StdFarMemSet( ConfigData->ZKontCheckListe, TRUE, sizeof( ConfigData->ZKontCheckListe ) );
		}
	    DosClose( TMSZKontFile );

	    ReadPathFileEntry( TMSPRINTERINFONO, FileName, FALSE );
	    ReadPathFileEntry( TMSPRINTERPORTNO, PrinterPort, TRUE );
	    GetPrinterInfo( FileName, PrinterPort );

	    ClosePathFile();

	    LoadList( BEGRUENDUNGEN );
	    LoadList( ABTEILUNGEN );
	    LoadList( ZEITKONTI );

	    WinString( Desktop, "������������������������������������Ŀ", CENTER, 0,  3 );
	    WinString( Desktop, "�                                    �", CENTER, 0,  4 );
	    WinString( Desktop, "�      Statistik - Generierung       �", CENTER, 0,  5 );
	    WinString( Desktop, "�      �����������������������       �", CENTER, 0,  6 );
	    WinString( Desktop, "�                und                 �", CENTER, 0,  7 );
	    WinString( Desktop, "�                ���                 �", CENTER, 0,  8 );
	    WinString( Desktop, "�     Verwaltung der Exportdaten     �", CENTER, 0,  9 );
	    WinString( Desktop, "�     ��������������������������     �", CENTER, 0, 10 );
	    WinString( Desktop, "�                                    �", CENTER, 0, 11 );
	    WinString( Desktop, "�              von TMS               �", CENTER, 0, 12 );
	    WinString( Desktop, "�                                    �", CENTER, 0, 13 );
	    WinString( Desktop, "��������������������������������������", CENTER, 0, 14 );

	    WinString( Desktop, " (c) Copyright 1992, 1993 J.Skripsky  ", CENTER, 0, 16 );

	    WinString( Desktop, "      Designed and Developed by       ", CENTER, 0, 18 );
	    WinString( Desktop, "           Juraj Skripsky             ", CENTER, 0, 19 );
	    WinString( Desktop, "         CH-8952 Schlieren            ", CENTER, 0, 20 );

	    BiosGetKey();
	    WinFill( Desktop, SPACECHAR, 0, 0, WinGetx2( Desktop ), WinGety2( Desktop ) );

	    WinFill( Desktop, '�', 0, 22, 79, 22 );

	    WinFill( Desktop, '�', 27,	0, 27, 21 );
	    WinFill( Desktop, '�',  0, 22, 79, 22 );
	    WinCreateWindow( Desktop, &Menu, MenuProc, 0, 0, 1, 1, 25, 20 );

	    WinSendMsg( Menu, WM_SHOW, 0, 0 );
	    WinSendMsg( Menu, WM_SETFOCUS, 0, 0 );

	    do
		{
		Key = BiosGetKey();
		Msg = WinSendMsg( Menu, WM_CHAR, (MPARAM)Key, 0 );
		}
	    while( (WORD)Msg != KBESC );


	    FreeList( BEGRUENDUNGEN );
	    FreeList( ABTEILUNGEN );
	    FreeList( ZEITKONTI );

	    FreePrinterInfo();

	    WinDestroyWindow( Menu );
	    break;
	 }

    if( !WriteConfigData() )
	; // Debug!!!!!

    WinDestroyWindow( Bottomline );
    WinDestroyWindow( Desktop );
    WinTerminate();
    }
Exemplo n.º 16
0
void CPrinterInfo::GetNames(HGLOBAL hDevNames, BOOL fUseWinIni /*=TRUE*/)
{
/*
// In case we fail.
*/

	m_csDriverName.Empty();
	m_csDeviceName.Empty();
	m_csOutputName.Empty();
	m_csPrinterName.Empty();

/*
// Now try and get the printer info.
*/

	LPDEVNAMES pDevNames = NULL;

	if (hDevNames != NULL)
	{
		pDevNames = (LPDEVNAMES)::GlobalLock(hDevNames);
	}

	CString csWinDevice;
	CString csWinDriver;
	CString csWinOutput;

	if (fUseWinIni)
	{
		char szBuffer[256];
		::GetProfileString("windows", "device", "?", szBuffer, sizeof(szBuffer));
		if (strcmp(szBuffer, "?") != 0)
		{
			csWinDevice = strtok(szBuffer, ",");
			csWinDriver = strtok(NULL, ",");
			csWinOutput = strtok(NULL, ",");
		}
	}

	if (pDevNames == NULL)
	{
	/*
	// We don't have a printer name. Use defaults.
	*/
		TRACE0("*** Using WIN.INI ***\n");
		m_csDeviceName = csWinDevice;
		m_csDriverName = csWinDriver;
		m_csOutputName = csWinOutput;
	}
	else
	{
	/* Extract the driver name. */

		m_csDeviceName = (LPCSTR)pDevNames + pDevNames->wDeviceOffset;
		m_csDriverName = (LPCSTR)pDevNames + pDevNames->wDriverOffset;
		m_csOutputName = (LPCSTR)pDevNames + pDevNames->wOutputOffset;

		::GlobalUnlock(hDevNames);

	}

#ifdef WIN32

/*
// We don't want this transient WINSPOOL name.
// If it shows up, go back to the WIN.INI device= name if we have one.
*/
	if (m_csDriverName.CompareNoCase("WINSPOOL") == 0)
	{
		if (!csWinDriver.IsEmpty())
		{
			m_csDriverName = csWinDriver;
		}
	}

	m_csPrinterName = m_csDeviceName;

/*
// Get the actual driver name (not the name the user gave it).
*/
	HANDLE hPrinter;
	if (OpenPrinter((LPSTR)(LPCSTR)m_csDeviceName, &hPrinter, NULL))
	{
		PRINTER_INFO_2* pInfo2;
		if ((pInfo2 = (PRINTER_INFO_2*)GetPrinterInfo(hPrinter, 2)) != NULL)
		{
			if (pInfo2->pDriverName != NULL)
			{
				m_csDeviceName = pInfo2->pDriverName;
			}
			delete [] pInfo2;
		}
		DRIVER_INFO_2* pDrvInfo2;
		if ((pDrvInfo2 = (DRIVER_INFO_2*)GetDriverInfo(hPrinter, 2)) != NULL)
		{
			if (pDrvInfo2->pDriverPath != NULL)
			{
				m_csDriverName = pDrvInfo2->pDriverPath;
			}
			delete [] pDrvInfo2;
		}
		ClosePrinter(hPrinter);
	}
#else
	m_csPrinterName = m_csDeviceName;
#endif

   CString csOutput;
   csOutput.Format("Drv: '%s'; Dev: '%s'; Out: '%s'\n(Name: '%s')",
			         (LPCSTR)m_csDriverName,
			         (LPCSTR)m_csDeviceName,
			         (LPCSTR)m_csOutputName,
						(LPCSTR)m_csPrinterName);
//	AfxMessageBox(csOutput);
   TRACE("%s\n", csOutput);
}
Exemplo n.º 17
0
/*++
*******************************************************************
    O p e n P r i n t P r o c e s s o r

    Routine Description:

    Arguments:
        pPrinterName            => name of printer we are
                                    opening for
        pPrintProcessorOpenData => information used for opening
                                    the print processor

    Return Value:
        PPRINTPROCESSORDATA => processor data of opened
                                processor if successful
        NULL if failed - caller uses GetLastError for reason

    NOTE: OpenPrinter will be called iff this returns a valid handle
          (and we're not journal)

*******************************************************************
--*/
HANDLE
OpenPrintProcessor(
    _In_ LPWSTR                  pPrinterName,
    _In_ PPRINTPROCESSOROPENDATA pPrintProcessorOpenData
)
{
    PPRINTPROCESSORDATA pData;
    LPWSTR              *pMyDatatypes    = Datatypes;
    DWORD               uDatatype        = 0;
    HANDLE              hPrinter         = 0;
    HDC                 hDC              = 0;
    PDEVMODEW           pDevmode         = NULL;
    DWORD               dwNewDevmodeSize = 0;


    /** If the caller passed a NULL for the open data, fail the call.
        pPrintProcessorOpenData->pDevMode can be NULL **/

    if (!pPrintProcessorOpenData ||
        !pPrintProcessorOpenData->pDatatype ||
        !*pPrintProcessorOpenData->pDatatype) {

        SetLastError(ERROR_INVALID_PARAMETER);
        return NULL;
    }

    /** Search for the data type index we are opening for **/

    while (*pMyDatatypes) {

        if (!_wcsicmp(*pMyDatatypes,pPrintProcessorOpenData->pDatatype)) {
            break;
        }
        pMyDatatypes++;
        uDatatype++;
    }

    /** Allocate a buffer for the print processor data to return **/

    pData = (PPRINTPROCESSORDATA)AllocSplMem(sizeof(PRINTPROCESSORDATA));

    if (!pData) {
        ODS(("Alloc failed in OpenPrintProcessor, while printing on %ws\n", pPrinterName));
        return NULL;
    }

    ZeroMemory ( pData, sizeof (PRINTPROCESSORDATA) );

    /** Open the processor accordingly **/

    switch (uDatatype) {

    case PRINTPROCESSOR_TYPE_RAW:
        if (!OpenPrinter(pPrinterName, &hPrinter, NULL))
            goto Fail;
        break;

    case PRINTPROCESSOR_TYPE_EMF_50_1:
    case PRINTPROCESSOR_TYPE_EMF_50_2:
    case PRINTPROCESSOR_TYPE_EMF_50_3:

        if(pPrintProcessorOpenData->pDevMode)
        {
            if ( ! SUCCEEDED ( DWordAdd(pPrintProcessorOpenData->pDevMode->dmSize,
                                        pPrintProcessorOpenData->pDevMode->dmDriverExtra,
                                        &dwNewDevmodeSize) )
                 ||

                 (NULL == (pDevmode=(PDEVMODE)AllocSplMem( dwNewDevmodeSize ) ) )
               )
            {
                goto Fail;
            }
            memcpy(pDevmode,
                   pPrintProcessorOpenData->pDevMode,
                   pPrintProcessorOpenData->pDevMode->dmSize+
                   pPrintProcessorOpenData->pDevMode->dmDriverExtra);
        }
        break;

    case PRINTPROCESSOR_TYPE_TEXT:
        if ((hDC = CreateDC(
                 L"", pPrinterName, L"",
                 pPrintProcessorOpenData->pDevMode))
            == NULL)
            goto Fail;
        break;

    default:
        SetLastError(ERROR_INVALID_DATATYPE);
        goto Fail;
    }

    /** Fill in the print processors information **/

    pData->cb          = sizeof(PRINTPROCESSORDATA);
    pData->signature   = PRINTPROCESSORDATA_SIGNATURE;
    pData->JobId       = pPrintProcessorOpenData->JobId;
    pData->hPrinter    = hPrinter;
    pData->semPaused   = CreateEvent(NULL, TRUE, TRUE,NULL);
    pData->uDatatype   = uDatatype;
    pData->hDC         = hDC;
    pData->Copies      = 1;
    pData->TabSize     = BASE_TAB_SIZE;

    /** Allocate and fill in the processors strings **/

    pData->pPrinterName = AllocSplStr(pPrinterName);
    pData->pDatatype    = AllocSplStr(pPrintProcessorOpenData->pDatatype);
    pData->pDocument    = AllocSplStr(pPrintProcessorOpenData->pDocumentName);
    pData->pOutputFile  = AllocSplStr(pPrintProcessorOpenData->pOutputFile);
    pData->pParameters  = AllocSplStr(pPrintProcessorOpenData->pParameters);
    pData->pDevmode     = pDevmode;
    pData->pPrinterNameFromOpenData = AllocSplStr(pPrintProcessorOpenData->pPrinterName);

    //
    // Check for validity of pData. In the AllocSplStr above, if RHS is non-null, then LHS
    // should be non-null.
    //
    if ( NULL == pData->semPaused ||
        ( NULL != pPrinterName                           && NULL == pData->pPrinterName )  ||
        ( NULL != pPrintProcessorOpenData->pDatatype     && NULL == pData->pDatatype    )  ||
        ( NULL != pPrintProcessorOpenData->pDocumentName && NULL == pData->pDocument    )  ||
        ( NULL != pPrintProcessorOpenData->pOutputFile   && NULL == pData->pOutputFile  )  ||
        ( NULL != pPrintProcessorOpenData->pParameters   && NULL == pData->pParameters  )  ||
        ( NULL != pPrintProcessorOpenData->pPrinterName  && NULL == pData->pPrinterNameFromOpenData)
      )
    {
        goto Fail;
    }


    /** Parse the parameters string **/
    if (pData->pParameters) {
        ULONG   value;
        USHORT  length = sizeof(ULONG);

        /**
            Look to see if there is a COPIES=n key/value in the
            Parameters field of this job.  This tells us the number
            of times to play the data.
        **/

        if (pData->pParameters) {

            GetKeyValue(pData->pParameters,
                        pCopiesKey,
                        VALUE_ULONG,
                        &length,
                        &value);

            if (length == sizeof(ULONG)) {
                pData->Copies = value;
            }
        }

        /** If this is a text job, see if the tab size is in there **/

        if (uDatatype == PRINTPROCESSOR_TYPE_TEXT) {
            length = sizeof(ULONG);

            GetKeyValue(pData->pParameters,
                        pTabsKey,
                        VALUE_ULONG,
                        &length,
                        &value);

            if ((length == sizeof(ULONG)) && value) {
                pData->TabSize = value;
            }
        }
    } /* If we have a parameter string */

    /**
        If we are doing copies, we need to check to see if
        this is a direct or spooled job.  If it is direct, then
        we can't do copies because we can't rewind the data stream.
    **/

    if (pData->Copies > 1) {
        ULONG           Error;
        PPRINTER_INFO_2 pPrinterInfo2;

        /** If we don't already have the printer open, open it **/

        if (uDatatype != PRINTPROCESSOR_TYPE_RAW
            ) {

            OpenPrinter(pPrinterName, &hPrinter, NULL);
        }
        if (hPrinter && hPrinter != INVALID_HANDLE_VALUE) {

            /** Get the printer info - this returns an allocated buffer **/

            pPrinterInfo2 = (PPRINTER_INFO_2)GetPrinterInfo(hPrinter, 2, &Error);

            /** If we couldn't get the info, be safe and don't do copies **/

            if (!pPrinterInfo2) {
                ODS(("GetPrinter failed - falling back to 1 copy\n"));
                pData->Copies = 1;
            }
            else {
                if (pPrinterInfo2->Attributes & PRINTER_ATTRIBUTE_DIRECT) {
                    pData->Copies = 1;
                }
                FreeSplMem((PUCHAR)pPrinterInfo2);
            }

            /** If we just opened the printer, close it **/

            if (uDatatype != PRINTPROCESSOR_TYPE_RAW
                ) {

                ClosePrinter(hPrinter);
            }
        }
        else {
            pData->Copies = 1;
        }
    }

    return (HANDLE)pData;

Fail:
    BReleasePPData(&pData);

    return FALSE;
}