472,145 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;

namespace WindowsApplication1
{
static class Program
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct tagLABELINFO
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String LabelName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String PaperName;
public object PaperSize;
public object BitmapSize;
public int LabelCount;
public object LabelSize;
} // tagLABELINFO

[StructLayout(LayoutKind.Sequential)]
public struct TObjectID
{
public int oID;
} // TObjectID

[StructLayout(LayoutKind.Sequential)]
public struct posCoordinates
{
public int xPos;
public int yPos;
public int Width;
public int Height;
}//posCoordinates

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct tagObjectInfo
{
public TObjectID ObjID;
public int ObjType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String ObjName;
public posCoordinates posCoordinates;
public int Rotate;
} // tagObjectInfo

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TTextBlockAttributes
{
[MarshalAs(UnmanagedType.LPStr)]
public String Text;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String Font1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String Font2;
public int Justify;
public int VertJustify;
public bool bMirrored;
public bool bVerticalText;
public bool IsRichText;
public int Effects;
} // TTextBlockAttributes

[StructLayout(LayoutKind.Sequential)]
public struct TAddressAttributes
{
public TTextBlockAttributes TextInfo;
public int BarCodePos;
public bool b9DigitOnly;
} // TAddressAttributes

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TLineAttributes
{
public int Length;
public int Orient;
public int Thickness;
} // TLineAttributes

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TCounterAttributes
{
public TTextBlockAttributes TextInfo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public String PreText;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public String PostText;
public int Start;
public int Current;
public int Width;
public int Increment;
bool bLeadingZeros;
} // TCounterAttributes

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct TDateTimeAttributes
{
public TTextBlockAttributes TextInfo;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public String PreText;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public String PostText;
public int DateFormat;
public bool bIncludeTime;
public bool b24Hour;
} // TDateTimeAttributes

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct tagTBarcodeAttributes
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public String Text;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public String Font;
public int HRTextPos;
public int BCType;
public int BCRatio;
public int Justify;
public TObjectID Link;
} // TBarcodeAttributes

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

[DllImport("labels.dll")]
static extern bool DeleteLabelObject(TObjectID ID);

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

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

[DllImport("labels.dll")]
static extern bool SetAttributes(ref TObjectID ID, IntPtr Attrib);

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

TTextBlockAttributes txtAttribute = new TTextBlockAttributes();

txtAttribute.Text = "Hello World \r\n Good Morning \r\n";
txtAttribute.Font1 = "Times New Roman, 10, Bold" + '\0';
txtAttribute.Font2 = "Times New Roman, 10, Bold" + '\0';
txtAttribute.Justify = 0;
txtAttribute.VertJustify = 0;
txtAttribute.bMirrored = false;
txtAttribute.bVerticalText = false;
txtAttribute.IsRichText = false;
txtAttribute.Effects = 0;

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

TObjectID to = new TObjectID();

IntPtr mypointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TTextBl ockAttributes)));

Marshal.StructureToPtr(txtAttribute, mypointer, true);

txtAttribute = (TTextBlockAttributes)Marshal.PtrToStructure(mypoi nter, typeof(TTextBlockAttributes));

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

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

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

Marshal.FreeHGlobal(mypointer);

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

}
}
}
Apr 30 '08 #1
0 1512

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Developwebsites | last post: by
7 posts views Thread by Ira S | last post: by
3 posts views Thread by Michael | last post: by
16 posts views Thread by scott | last post: by
reply views Thread by anonymous | last post: by
3 posts views Thread by postrishi | last post: by
1 post views Thread by ARC | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.