通过ShellExecute()打印到Dymo LabelWriter Turbo时的随机延迟

时间:2009-11-23 15:42:30

标签: c++ c++builder shellexecute

我有一个外部程序,它接受一些参数(PrintLabel),它是使用ShellExecute从我的应用程序调用的。 PrintLabel如下所示。有时打印标签可能需要15到20秒。随着时间的推移似乎会变得更糟。如果重新启动PC,则打印速度会再次加快,但随着时间的推移会逐渐变慢。有时它是随机的(即快速然后慢)。我正在使用SW_HIDE,因为我不希望用户每次都看到控制台对话框。我知道它应该像普通打印机一样需要几秒钟,但15 - 20秒似乎过度。它是Dymo LabelWriter问题还是ShellExecute问题?在UI线程中调用ShellExecute。有线索吗?

来自应用程序的ShellExecute语句:

ShellExecute(Application->Handle, "open", "C:\\Program Files\\Application\\PrintLabel", objdata, "C:\\Program Files\\Application", SW_HIDE);

PrintLabel代码:

...

m_DymoAddIn.Print2(Copies, false, Tray);

...

这是CDymoAddIn4.h:

// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard

// CDymoAddIn4 wrapper class

class CDymoAddIn4 : public COleDispatchDriver
{
public:
    CDymoAddIn4(){} // Calls COleDispatchDriver default constructor
    CDymoAddIn4(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    CDymoAddIn4(const CDymoAddIn4& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

    // Attributes
public:

    // Operations
public:


    // IDymoAddIn4 methods
public:
    BOOL Open(LPCTSTR FileName)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0x1, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, FileName);
        return result;
    }
    BOOL Save()
    {
        BOOL result;
        InvokeHelper(0x2, DISPATCH_METHOD, VT_BOOL, (void*)&result, NULL);
        return result;
    }
    BOOL SaveAs(LPCTSTR FileName)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0x3, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, FileName);
        return result;
    }
    BOOL Print(long Copies, BOOL bShowDialog)
    {
        BOOL result;
        static BYTE parms[] = VTS_I4 VTS_BOOL ;
        InvokeHelper(0x4, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, Copies, bShowDialog);
        return result;
    }
    void Hide()
    {
        InvokeHelper(0x5, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    void Show()
    {
        InvokeHelper(0x6, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    void SysTray(BOOL State)
    {
        static BYTE parms[] = VTS_BOOL ;
        InvokeHelper(0x7, DISPATCH_METHOD, VT_EMPTY, NULL, parms, State);
    }
    void Quit()
    {
        InvokeHelper(0x8, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    CString get_FileName()
    {
        CString result;
        InvokeHelper(0x9, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
        return result;
    }
    BOOL SelectPrinter(LPCTSTR Printer)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0xa, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, Printer);
        return result;
    }
    CString GetDymoPrinters()
    {
        CString result;
        InvokeHelper(0xb, DISPATCH_METHOD, VT_BSTR, (void*)&result, NULL);
        return result;
    }
    CString GetMRULabelFiles()
    {
        CString result;
        InvokeHelper(0x12d, DISPATCH_METHOD, VT_BSTR, (void*)&result, NULL);
        return result;
    }
    BOOL Open2(LPCTSTR FileName)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0x12e, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, FileName);
        return result;
    }
    long GetMRULabelFileCount()
    {
        long result;
        InvokeHelper(0x12f, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }
    CString GetMRULabelFileName(long Index)
    {
        CString result;
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x130, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, Index);
        return result;
    }
    BOOL OpenMRULabelFile(long Index)
    {
        BOOL result;
        static BYTE parms[] = VTS_I4 ;
        InvokeHelper(0x131, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, Index);
        return result;
    }
    BOOL OpenMRULabelFileByName(LPCTSTR FileName)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0x132, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, FileName);
        return result;
    }
    BOOL Print2(long Copies, BOOL bShowDlg, long Tray)
    {
        BOOL result;
        static BYTE parms[] = VTS_I4 VTS_BOOL VTS_I4 ;
        InvokeHelper(0x191, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, Copies, bShowDlg, Tray);
        return result;
    }
    long GetCurrentPaperTray()
    {
        long result;
        InvokeHelper(0x192, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
        return result;
    }
    void StartPrintJob()
    {
        InvokeHelper(0xc9, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    void EndPrintJob()
    {
        InvokeHelper(0xca, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
    }
    BOOL IsTwinTurboPrinter(LPCTSTR PrinterName)
    {
        BOOL result;
        static BYTE parms[] = VTS_BSTR ;
        InvokeHelper(0xcb, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, PrinterName);
        return result;
    }
    CString GetCurrentPrinterName()
    {
        CString result;
        InvokeHelper(0xce, DISPATCH_METHOD, VT_BSTR, (void*)&result, NULL);
        return result;
    }

    // IDymoAddIn4 properties
public:

};

2 个答案:

答案 0 :(得分:2)

添加对StartPrintJob()和EndPrintJob()的调用。有时当你向系统发送数据时,它会假设你要发送更多信息并只缓存数据 - 你需要一种方式来说嘿我已经完成了让我们做这件事。

还有一些元建议 - 确保你继续尝试 - 并尝试将你的问题减少到可能的最小例子,以消除你的思想,并专注于一组最小的问题元素

(见本答案的成因问题评论)

答案 1 :(得分:0)

问题发生之前会打印多少个标签?这可能是导致打印速度变慢的内存/句柄泄漏吗?你是否正确释放所有COM对象?您是否使用ProcessExplorer或任务管理器检查了资源使用情况?