Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 #1Unfortunately 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) Thenin 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

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

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.

![]() |
batch parameter space
|
VB; Regex class can't be ...
|

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