467,080 Members | 957 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,080 developers. It's quick & easy.

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
  • viewed: 1369
Share:

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@skwc.com | last post: by
reply views Thread by anonymous | last post: by
3 posts views Thread by postrishi@gmail.com | last post: by
1 post views Thread by ARC | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.