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.
----------------------------------------------
> One question: When you used this code how did you get around the
> following
[quoted text clipped - 17 lines]
> Bill Angus, MA
> http://www.psychtest.com
Bill Angus - 15 Jan 2007 23:52 GMT
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 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
[quoted text clipped - 60 lines]
> > Bill Angus, MA
> > http://www.psychtest.com
RobinS - 16 Jan 2007 06:08 GMT
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.
--------------------
> 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
[quoted text clipped - 73 lines]
>> > Bill Angus, MA
>> > http://www.psychtest.com