Computing.Net > Forums > Programming > Issues printing raw data in VB.Net

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Issues printing raw data in VB.Net

Reply to Message Icon

Name: byrnesit
Date: August 17, 2007 at 00:44:36 Pacific
OS: XP Pro
CPU/Ram: PM1.7
Product: Dell Latitude D600
Comment:

Hi People,
I'm having a bit of a problem. I'm just starting to merge from VB6 to VB.net and I am wanting to print raw data to a receipt printer (and I need to send the raw data as I need to use ESC/POS escape commands etc). In VB6 I used to do it a bit dodgy by simply going
Open "LPT1:" For Output as #1
Print #1, "Blah!"
Print #1, ""
Print #1, Chr(27) & "i" 'ESC i - advance and cut paper
Close #1

Unfortunately this doesnt work in .Net with good reason, so I went searching on how to do it and found this:

http://support.microsoft.com/?scid=...

This looked very promising as it had a basically cut'n'paste class for me to use and I got all excited until I got the following error:
---
A call to PInvoke function 'WindowsApplication1!WindowsApplication1.RawPrinterHelper::OpenPrinter' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
---

This happens on the line:
If OpenPrinter(szPrinterName, hPrinter,0) Then

in the 'SendBytesToPrinter' function

As I have little knowledge of what is going on here I thought someone may be able to help?

I have tried printing to multiple printers and get the same error.

If anyone could help me out that would be great:)

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: August 18, 2007 at 03:10:01 Pacific
Reply:

Fixed it. Change this DLL import to the following:
(To locate the DLL import, right-click on OpenPrinter and select "Go To Definition.")

<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As IntPtr) As Boolean
End Function


0

Response Number 2
Name: byrnesit
Date: August 20, 2007 at 05:44:55 Pacific
Reply:

Thanks for this, I was just logging in to say that i had worked around it but I will give this a go now, will probably be more reliable than the code I hacked together.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


batch parameter space VB; Regex class can't be ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Issues printing raw data in VB.Net

Printer paper collection in VB.NET www.computing.net/answers/programming/printer-paper-collection-in-vbnet/11265.html

call method written in VB.NET from www.computing.net/answers/programming/call-method-written-in-vbnet-from-/7816.html

How to delete in VB.NET www.computing.net/answers/programming/how-to-delete-in-vbnet/14490.html