English 中文(简体)
Random Delay When Printing to Dymo LabelWriter Turbo Via ShellExecute()
原标题:

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:

};
最佳回答

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)

问题回答

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?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签