Is .NET no good for some things?

  • Thread starter Thread starter Bill Angus
  • Start date Start date
B

Bill Angus

It used to be simple in Basic to "open" a printer (like LPT1), then "write" ASCII characters to it. Alternatively, one could create a text-file, then a simple DOS copy operation could copy the text file to a printer using shell. There is no documentation to indicate how this might still be accomplished

Does anybody know if one can still "copy" a file to a windows printer i.e. use shell to dump a text file to a device (e.g. \\main\HP Laser which might be a printer attached to one of the nodes of the network or perhaps to 192.168.1.20 which might be the IP address for a network printer)? I believe copy can still be done if one maps a device to LPT1 or something. However, I'm not sure about how to do this using the network name or the IP address of the printer if it is not connected as a shared resource of a PC

Thanks and have a great day!

Bill Angus, MA
http://www.psychtest.com
 
Try this link. This shows how to use RawPrinting.

http://support.microsoft.com/?id=322090

BTW, please post your messages in text format; not everybody's
newsreader handles html.

Thanks,
Robin S.
------------------------------
It used to be simple in Basic to "open" a printer (like LPT1), then
"write" ASCII characters to it. Alternatively, one could create a
text-file, then a simple DOS copy operation could copy the text file to
a printer using shell. There is no documentation to indicate how this
might still be accomplished

Does anybody know if one can still "copy" a file to a windows printer
i.e. use shell to dump a text file to a device (e.g. \\main\HP Laser
which might be a printer attached to one of the nodes of the network or
perhaps to 192.168.1.20 which might be the IP address for a network
printer)? I believe copy can still be done if one maps a device to LPT1
or something. However, I'm not sure about how to do this using the
network name or the IP address of the printer if it is not connected as
a shared resource of a PC

Thanks and have a great day!

Bill Angus, MA
http://www.psychtest.com
 
GREAT: THANKS V. MUCH !!

Bill Angus
----- Original Message -----
From: RobinS
Newsgroups: microsoft.public.dotnet.framework.windowsforms
Sent: Friday, January 12, 2007 9:45 AM
Subject: Re: Is .NET no good for some things?


Try this link. This shows how to use RawPrinting.

http://support.microsoft.com/?id=322090

BTW, please post your messages in text format; not everybody's
newsreader handles html.

Thanks,
Robin S.
 
I got that from Tim Patrick's start-to-finish vb2005 book; he has an
example of how to use it in his book, and references the article on
msdn.
I hope it helps.

Robin S.
 
One question: When you used this code how did you get around the following
error ...

A call to PInvoke function
'ProfitMaster!PM_Namspace.PM_Module+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.

which occurs when the following line of code is accessed ....

If OpenPrinter(szPrinterName, hPrinter, 0) Then ...
 
I got this from Tim Patrick's book and it just works for me. I printed
out the article and looked at the changes. He uses it almost
identically,
except for a few changes.

He changed the routine SendBytesToPrinter. He renamed it
SendStringToPrinter. Here's the header:

Public Shared Function SendStringToPrinter(ByVal targetPrinter As
String, _
ByVal stringContent As String, ByVal documentTitle As String) as
Boolean

He added the following definitions at the top:

Dim contentBytes as IntPtr
Dim contentSize as Int32

Before the line that initializes bSuccess = False, he added this:

'Convert the string to ANSI text.
contentSize = stringContent.Length()
contentBytes = Marshal.StringToCoTaskMemAnsi(stringContent)

After "Write your printer-specific bytes to the printer" the article
has this: bSuccess = WritePrinter(hPrinter, pBytes, dwCount, dwWritten)
but Tim has this:

bSuccess = WritePrinter(hPrinter, contentByes, contentSize, dwWritten)

Then at the end before returning bSuccess, he has

'Free up unused memory.
Marshal.FreeCoTaskmem(contentBytes)

This was a VB2005 book, and I don't know if the changes had something
to do with that, or because the MSDN article didn't work exactly right.

Does this help?

Robin S.
 
You've been a big help Robin. I've ordered the book since you found a
solution to the problem in it and it works for you. There may be some
confusion in the email below, because there must be more or different
changes that the ones you listed.

Thanks again.
 
I hope it helps you. He's using it to print bar codes, which
I thought was pretty cool. He also puts his e-mail address
in the book, and if you can't get it to work right, try
e-mailing him and see if he has any more detail that would help.

Robin S.
--------------------
 
Back
Top