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

发布于 2024-08-12 07:49:30 字数 5375 浏览 4 评论 0原文

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

应用程序中的 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:

};

I have an external program which takes in a few arguments (PrintLabel) which is called from my application using ShellExecute. PrintLabel is shown below. Sometimes it can take upwards to 15 to 20 seconds to print a label. It seems to get worse over time. If the PC is rebooted, then the printing speeds up again but it gets slower over time. Sometimes it is random (i.e. fast then slow). I am using SW_HIDE because I do not want the user to see the console dialog box everytime. I understand it should take a few seconds like a normal printer would, but 15 - 20 seconds seems excessive. Is it a Dymo LabelWriter issue or ShellExecute issue? ShellExecute is called within the UI thread. Any clues?

ShellExecute statement from application:

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

PrintLabel Code:

...

m_DymoAddIn.Print2(Copies, false, Tray);

...

Here is the 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:

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心房的律动 2024-08-19 07:49:30

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

还有一些元建议 - 确保你不断尝试 - 并尝试将你的问题减少到尽可能最小的例子,以理清你的思维并专注于最少的问题元素集

(请参阅对问题的评论以了解此答案的起源)

Add calls to StartPrintJob() and EndPrintJob(). Sometimes when you send data to a system it will assume you are going to send more and just cache the data - you need a way to say hey I'm done let's do this thing.

And a bit of meta-advice - Make sure you keep experimenting - and try to reduce your problem to the smallest example possible to de-clutter your mind and focus on a minimal set of problem elements

(See comments to Question for genesis of this Answer)

孤云独去闲 2024-08-19 07:49:30

在问题出现之前打印了多少标签?这是否是内存/句柄泄漏导致打印速度减慢?您是否正确释放了所有 COM 对象?您是否使用 ProcessExplorer 或任务管理器检查过资源使用情况?

How many labels are printed before the issue arises? Could this be a memory/handle leak that is causing printing to slow down? Are you freeing all COM objects properly? Have you checked resource usage with ProcessExplorer or Task Manager?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文