Exemplo n.º 1
0
/*++

Routine Name:

    ConfigureLPTPortInitDialog

Routine Description:

    Initializes the lpt port configuration dialog variables.

Arguments:

    hDlg    - handle to dialog
    pPort   - pointer to port dialog data to initialize.

Return Value:

    TRUE data was initlaized, FALSE error occurred.

--*/
BOOL
ConfigureLPTPortInitDialog(
            HWND        hwnd,
    _In_    PPORTDIALOG pPort
    )
{
    DWORD dwTransmissionRetryTimeout;
    DWORD cbNeeded;
    DWORD dwDummy = 0;
    BOOL  rc;
    DWORD dwStatus = NO_ERROR;

    DBGMSG(DBG_TRACE, ("ConfigureLPTPortInitDialog\n"));

    SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pPort);

    SetForegroundWindow(hwnd);

    SendDlgItemMessage( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
                        EM_LIMITTEXT, TIMEOUT_STRING_MAX, 0 );

    //
    // Get the Transmission Retry Timeout from the host
    //
    rc = XcvData(   pPort->hXcv,
                    L"GetTransmissionRetryTimeout",
                    (PBYTE) &dwDummy,
                    0,
                    (PBYTE) &dwTransmissionRetryTimeout,
                    sizeof dwTransmissionRetryTimeout,
                    &cbNeeded,
                    &dwStatus);
    if(!rc) {
        DBGMSG(DBG_WARN, ("Error %d checking TransmissionRetryTimeout\n", GetLastError()));
    } else if(dwStatus != ERROR_SUCCESS) {
        DBGMSG(DBG_WARN, ("Error %d checking TransmissionRetryTimeout\n", dwStatus));
        SetLastError(dwStatus);
        rc = FALSE;

    } else {

        SetDlgItemInt( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
                       dwTransmissionRetryTimeout, FALSE );

        SET_LAST_VALID_ENTRY( hwnd, IDD_CL_EF_TRANSMISSIONRETRY,
                              dwTransmissionRetryTimeout );

    }

    return rc;
}
Exemplo n.º 2
0
/*++

Routine Name:

    ConfigureLPTPortCommandOK

Routine Description:

    Handles the completion of the lpt port configuration dialog.

Arguments:

    hDlg    - handle to dialog

Return Value:

    TRUE success, FALSE an error occurred.

--*/
BOOL
ConfigureLPTPortCommandOK(
    HWND hwnd
    )
{
    WCHAR String[TIMEOUT_STRING_MAX+1];
    UINT  TransmissionRetryTimeout;
    BOOL  b = FALSE;
    DWORD cbNeeded;
    PPORTDIALOG pPort;
    DWORD dwStatus = NO_ERROR;
    size_t cbSize = 0;

    if ((pPort = (PPORTDIALOG) GetWindowLongPtr(hwnd, GWLP_USERDATA)) == NULL)
    {
        dwStatus = ERROR_INVALID_DATA;
        ErrorMessage (hwnd, dwStatus);
        SetLastError (dwStatus);
        return FALSE;
    }

    TransmissionRetryTimeout = GetDlgItemInt( hwnd,
                                              IDD_CL_EF_TRANSMISSIONRETRY,
                                              &b,
                                              FALSE );

    (VOID) StringCchPrintf (String, COUNTOF (String), L"%u", TransmissionRetryTimeout);

    cbSize = (wcslen(String) + 1) * sizeof(WCHAR);
    if (cbSize <= DWORD_MAX)
    {
        b = XcvData(pPort->hXcv,
                    L"ConfigureLPTPortCommandOK",
                    (PBYTE) String,
                    (DWORD)cbSize,
                    (PBYTE) &cbNeeded,
                    0,
                    &cbNeeded,
                    &dwStatus);
    }
    else
    {
        SetLastError(ERROR_INVALID_DATA);
    }

    EndDialog(hwnd, b ? dwStatus : GetLastError());

    return TRUE;
}
Exemplo n.º 3
0
OSStatus
CPrinterSetupWizardSheet::InstallPrinterPDLAndLPR(Printer * printer, Service * service, DWORD protocol )
{
	PRINTER_DEFAULTS	printerDefaults =	{ NULL,  NULL, SERVER_ACCESS_ADMINISTER };
	DWORD				dwStatus;
	DWORD				cbInputData		=	100;
	PBYTE				pOutputData		=	NULL;
	DWORD				cbOutputNeeded	=	0;
	PORT_DATA_1			portData;
	PRINTER_INFO_2		pInfo;
	HANDLE				hXcv			=	NULL;
	HANDLE				hPrinter		=	NULL;
	Queue			*	q;
	BOOL				ok;
	OSStatus			err;

	check(printer != NULL);
	check(printer->installed == false);

	q = service->queues.front();
	check( q );

	ok = OpenPrinter(L",XcvMonitor Standard TCP/IP Port", &hXcv, &printerDefaults);
	err = translate_errno( ok, errno_compat(), kUnknownErr );
	require_noerr( err, exit );

	//
	// BUGBUG: MSDN said this is not required, but my experience shows it is required
	//
	try
	{
		pOutputData = new BYTE[cbInputData];
	}
	catch (...)
	{
		pOutputData = NULL;
	}

	require_action( pOutputData, exit, err = kNoMemoryErr );
	
	//
	// setup the port
	//
	ZeroMemory(&portData, sizeof(PORT_DATA_1));
	wcscpy(portData.sztPortName, printer->portName);
    	
	portData.dwPortNumber	=	service->portNumber;
	portData.dwVersion		=	1;
    	
	portData.dwProtocol	= protocol;
	portData.cbSize		= sizeof PORT_DATA_1;
	portData.dwReserved	= 0L;
    	
	wcscpy(portData.sztQueue, q->name);
	wcscpy(portData.sztIPAddress, service->hostname); 
	wcscpy(portData.sztHostAddress, service->hostname);

	ok = XcvData(hXcv, L"AddPort", (PBYTE) &portData, sizeof(PORT_DATA_1), pOutputData, cbInputData,  &cbOutputNeeded, &dwStatus);
	err = translate_errno( ok, errno_compat(), kUnknownErr );
	require_noerr( err, exit );

	//
	// add the printer
	//
	ZeroMemory(&pInfo, sizeof(pInfo));
		
	pInfo.pPrinterName			=	printer->actualName.GetBuffer();
	pInfo.pServerName			=	NULL;
	pInfo.pShareName			=	NULL;
	pInfo.pPortName				=	printer->portName.GetBuffer();
	pInfo.pDriverName			=	printer->modelName.GetBuffer();
	pInfo.pComment				=	printer->displayModelName.GetBuffer();
	pInfo.pLocation				=	q->location.GetBuffer();
	pInfo.pDevMode				=	NULL;
	pInfo.pDevMode				=	NULL;
	pInfo.pSepFile				=	L"";
	pInfo.pPrintProcessor		=	L"winprint";
	pInfo.pDatatype				=	L"RAW";
	pInfo.pParameters			=	L"";
	pInfo.pSecurityDescriptor	=	NULL;
	pInfo.Attributes			=	PRINTER_ATTRIBUTE_QUEUED;
	pInfo.Priority				=	0;
	pInfo.DefaultPriority		=	0;
	pInfo.StartTime				=	0;
	pInfo.UntilTime				=	0;

	hPrinter = AddPrinter(NULL, 2, (LPBYTE) &pInfo);
	err = translate_errno( hPrinter, errno_compat(), kUnknownErr );
	require_noerr( err, exit );

exit:

	if (hPrinter != NULL)
	{
		ClosePrinter(hPrinter);
	}

	if (hXcv != NULL)
	{
		ClosePrinter(hXcv);
	}

	if (pOutputData != NULL)
	{
		delete [] pOutputData;
	}

	return err;
}
Exemplo n.º 4
0
/*++

Routine Name:

    PortNameCommandOK

Routine Description:

    Handles the case when the user clicks ok on the port name dialog

Arguments:

    hDlg    - handle to dialog

Return Value:

    TRUE success, FALSE an error occurred.

--*/
BOOL
PortNameCommandOK(
    HWND    hwnd
    )
{
    PPORTDIALOG pPort;
    WCHAR   string [MAX_LOCAL_PORTNAME + 1] = L"";
    WCHAR   trimmedString [MAX_LOCAL_PORTNAME + 1] = L"";
    WCHAR   szWideSpace[] = L" ";
    BOOL    rc;
    DWORD   cbNeeded;
    DWORD   dwStatus = NO_ERROR;
    DWORD   indexString = 0;
    DWORD   indexTrimmedString = 0;
    SHORT   end;
    size_t  cbSize = 0;

    if ((pPort = (PPORTDIALOG) GetWindowLongPtr( hwnd, GWLP_USERDATA )) == NULL)
    {
        dwStatus = ERROR_INVALID_DATA;
        ErrorMessage (hwnd, dwStatus);
        SetLastError (dwStatus);
        return FALSE;
    }

    GetDlgItemText( hwnd, IDD_PN_EF_PORTNAME, string, COUNTOF(string));
    string [COUNTOF (string) - 1] = L'\0';

    //
    // Trim the string for Spaces (Front & Back)
    //
    // First Cut off any spaces at the front
    //
    while ((indexString < COUNTOF(string)) &&
           (string[indexString] == szWideSpace[0]))
    {
        indexString++;
    }
    while ((indexString < COUNTOF(string)-1) && (string[indexString]))
    {
        trimmedString[indexTrimmedString++] = string[indexString++];
    }
    trimmedString[indexTrimmedString] = 0x00;

    //
    // Next Cut off any spaces at the end
    //
    end = (SHORT) wcslen(trimmedString)-1;
    while ((end >= 0) && (trimmedString[end] == szWideSpace[0]))
    {
        trimmedString[end--] = 0x00;
    }

    cbSize = (wcslen(string) + 1) * sizeof(*string);

    if (cbSize <= DWORD_MAX)
    {
        rc = XcvData(   pPort->hXcv,
                        L"PortIsValid",
                        (PBYTE) trimmedString,
                        (DWORD)cbSize,
                        (PBYTE) NULL,
                        0,
                        &cbNeeded,
                        &dwStatus);
    }
    else
    {
        rc = FALSE;
    }

    if (!rc) {
        return FALSE;

    } else if (dwStatus != ERROR_SUCCESS) {
        SetLastError(dwStatus);

        if ( (dwStatus == ERROR_INVALID_NAME) || (*trimmedString == 0x00) )
            Message( hwnd, MSG_ERROR, IDS_LOCALMONITOR, IDS_INVALIDPORTNAME_S, string );
        else
            ErrorMessage(hwnd, dwStatus);

        return FALSE;

    } else {
        pPort->pszPortName = AllocSplStr( trimmedString );
        pPort->dwRet = dwStatus;
        EndDialog( hwnd, ERROR_SUCCESS );
        return TRUE;
    }

}