Use Dymo Labelwriter Turbo in .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepa2Apr
    New Member
    • Apr 2008
    • 1

    #1

    Use Dymo Labelwriter Turbo in .net

    Hi,

    I'm trying to use a Dymo LabelWriter Turbo (Software version 4.1.0.0) on Windows XP, in my C# code. I'm able to detect the printer through my code. However it doesnt print anything. It tries to print, but the label doesnt have any text on it. Can anyone help me?

    Please find my code below.

    using System;
    using System.Collecti ons.Generic;
    using System.Windows. Forms;
    using System.Runtime. InteropServices ;
    using System.Text;

    namespace WindowsApplicat ion1
    {
    static class Program
    {
    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct tagLABELINFO
    {
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String LabelName;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String PaperName;
    public object PaperSize;
    public object BitmapSize;
    public int LabelCount;
    public object LabelSize;
    } // tagLABELINFO

    [StructLayout(La youtKind.Sequen tial)]
    public struct TObjectID
    {
    public int oID;
    } // TObjectID

    [StructLayout(La youtKind.Sequen tial)]
    public struct posCoordinates
    {
    public int xPos;
    public int yPos;
    public int Width;
    public int Height;
    }//posCoordinates

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct tagObjectInfo
    {
    public TObjectID ObjID;
    public int ObjType;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String ObjName;
    public posCoordinates posCoordinates;
    public int Rotate;
    } // tagObjectInfo

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct TTextBlockAttri butes
    {
    [MarshalAs(Unman agedType.LPStr)]
    public String Text;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String Font1;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String Font2;
    public int Justify;
    public int VertJustify;
    public bool bMirrored;
    public bool bVerticalText;
    public bool IsRichText;
    public int Effects;
    } // TTextBlockAttri butes

    [StructLayout(La youtKind.Sequen tial)]
    public struct TAddressAttribu tes
    {
    public TTextBlockAttri butes TextInfo;
    public int BarCodePos;
    public bool b9DigitOnly;
    } // TAddressAttribu tes

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct TLineAttributes
    {
    public int Length;
    public int Orient;
    public int Thickness;
    } // TLineAttributes

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct TCounterAttribu tes
    {
    public TTextBlockAttri butes TextInfo;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 32)]
    public String PreText;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 32)]
    public String PostText;
    public int Start;
    public int Current;
    public int Width;
    public int Increment;
    bool bLeadingZeros;
    } // TCounterAttribu tes

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct TDateTimeAttrib utes
    {
    public TTextBlockAttri butes TextInfo;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 32)]
    public String PreText;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 32)]
    public String PostText;
    public int DateFormat;
    public bool bIncludeTime;
    public bool b24Hour;
    } // TDateTimeAttrib utes

    [StructLayout(La youtKind.Sequen tial, CharSet = CharSet.Ansi)]
    public struct tagTBarcodeAttr ibutes
    {
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 256)]
    public String Text;
    [MarshalAs(Unman agedType.ByValT Str, SizeConst = 64)]
    public String Font;
    public int HRTextPos;
    public int BCType;
    public int BCRatio;
    public int Justify;
    public TObjectID Link;
    } // TBarcodeAttribu tes

    [DllImport("labe ls.dll")]
    static extern bool PrintLabel(Stri ng DeviceName, String Port, int
    Quantity, bool bShowDialog);

    [DllImport("labe ls.dll")]
    static extern bool DeleteLabelObje ct(TObjectID ID);

    [DllImport("labe ls.dll")]
    static extern IntPtr AddObject(Strin g ObjType, String ObjName, posCoordinates
    posCoordinates, int Rotation, IntPtr Attrib);

    [DllImport("labe ls.dll")]
    static extern void NewLabel(String Name);

    [DllImport("labe ls.dll")]
    static extern bool SetAttributes(r ef TObjectID ID, IntPtr Attrib);

    [STAThread]
    static void Main(string[] args)
    {
    // create a new label
    NewLabel("sunda y");

    TTextBlockAttri butes txtAttribute = new TTextBlockAttri butes();

    txtAttribute.Te xt = "Hello World \r\n Good Morning \r\n";
    txtAttribute.Fo nt1 = "Times New Roman, 10, Bold" + '\0';
    txtAttribute.Fo nt2 = "Times New Roman, 10, Bold" + '\0';
    txtAttribute.Ju stify = 0;
    txtAttribute.Ve rtJustify = 0;
    txtAttribute.bM irrored = false;
    txtAttribute.bV erticalText = false;
    txtAttribute.Is RichText = false;
    txtAttribute.Ef fects = 0;

    posCoordinates posCoordinates = new posCoordinates( );
    posCoordinates. xPos = 0;
    posCoordinates. yPos = 0;
    posCoordinates. Width = 60;
    posCoordinates. Height = 60;

    TObjectID to = new TObjectID();

    IntPtr mypointer = Marshal.AllocHG lobal(Marshal.S izeOf(typeof(TT extBlockAttribu tes)));

    Marshal.Structu reToPtr(txtAttr ibute, mypointer, true);

    txtAttribute = (TTextBlockAttr ibutes)Marshal. PtrToStructure( mypointer, typeof(TTextBlo ckAttributes));

    to.oID = (int)AddObject( "Text", "sunday", posCoordinates, 0, mypointer);

    Console.WriteLi ne("the new object ID is {0}", to.oID);

    bool printed = PrintLabel("Dym o LabelWriter Turbo-USB",
    null, 1, true);

    Marshal.FreeHGl obal(mypointer) ;

    Console.WriteLi ne("deleted is {0}", printed);

    }
    }
    }
Working...