2

我正在使用 Windows CE 6.0 在 ARM 平台上开发设备。目标之一是为用户提供直接从设备打印的可能性(而不仅仅是文本!)。这意味着,Windows 将不得不处理各种类型的打印机。我怎样才能实现这样的功能?

我的猜测是: - PCL 打印(你还能买到 PCL 打印机吗?) - 网络打印(怎么做 - 有什么例子吗?)

谢谢!

4

1 回答 1

4

在 Windows CE 6.0 下可以打印。在“\WINCE600\PUBLIC\COMMON\OAK\DRIVERS\PRINTER\PCL”中有一个 PCL 驱动程序的示例。要将其包含在 OS 设计中,请在 Configuraiton Properties --> Environment 中将 SYSGEN_PRINTING、SYSGEN_PCL 和 SYSGEN_USB_PRINTER 设置为 1。这将导致编译示例并将 pcl.dll 添加到 OS Design。还将添加 USB 打印机类驱动程序。

以上操作让我们以 ASCII 码打印文本:

    // initialize printing
    //hPrinter = CreateFile(L"LPT1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
    //if (hPrinter == NULL) RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): CreateFile() returned NULL"));

    // print text WORKS
    //WriteFile(hPrinter, szText, sizeof(szText), &cBytes, NULL);

    // close printer port
    //CloseHandle(hPrinter);

但是要打印例如 BMP 文件,我们需要真正使用 PCL 驱动程序(看下面的代码)。问题是,我无法摆脱一个错误:StartDoc() 总是返回“不支持网络请求”。开始打印作业的正确方法是什么?

    LPVOID lpMsgBuf = NULL;
    HDC hdc = NULL;
    DOCINFO di;
    DEVMODE dm;

    // initialize DEVMODE struct
    memset(&dm, 0, sizeof(DEVMODE));
    wcscpy(dm.dmDeviceName, L"Hewlett-Packard LaserJet P3010 Series");
    dm.dmSize = sizeof(DEVMODE);
    dm.dmPaperSize = DMPAPER_A4;
    dm.dmPrintQuality = DMRES_DRAFT;
    dm.dmFields = DM_PAPERSIZE | DM_PRINTQUALITY;

    //PAGESETUPDLG psd;
    //memset(&psd, 0, sizeof(psd));
    //psd.hwndOwner = NULL;
    //psd.hDevMode = NULL; 
    //psd.hDevNames = NULL;
    //psd.Flags = PSD_RETURNDEFAULT;
    //psd.lStructSize = sizeof(psd);

    //PageSetupDlg(&psd);
    //RETAILMSG(TRUE, (L"GUI: PageSetupDlg() result 0x%x", CommDlgExtendedError()));

    //if (psd.hDevMode == NULL) return -1;

    //DEVMODE* lpdm = (DEVMODE*)psd.hDevMode;

    DEVMODE* lpdm = &dm;

    // initialize device context
    hdc = CreateDC(L"pcl.dll", L"Printer", L"LPT1:", lpdm);
    if (hdc == NULL) {
        RETAILMSG(TRUE, (L"GUI: CreateDC() error 0x%x", GetLastError()));
        return -1;
    }

    // register abort procedure
    SetAbortProc(hdc, AbortProc);

    // initialize DOCINFO struct
    memset(&di, 0, sizeof(DOCINFO));
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = L"logo.bmp";
    di.lpszOutput = NULL;
    di.lpszDatatype = 0;
    di.fwType = 0;

    // print file
    if (StartDoc(hdc, &di) <= 0) {
        RETAILMSG(TRUE, (L"Error in OnClick5 (GUI): StartDoc() returned non-positive value"));
        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
            NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL);
        RETAILMSG(TRUE, ((LPWSTR)lpMsgBuf));
        LocalFree( lpMsgBuf );
        DeleteDC(hdc);
        return -1;
    }
于 2012-06-11T07:47:19.133 回答