PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Forms Is .NET no good for some things?

Reply

Is .NET no good for some things?

 
Thread Tools Rate Thread
Old 12-01-2007, 05:19 PM   #1
Bill Angus
Guest
 
Posts: n/a
Default Is .NET no good for some things?


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
  Reply With Quote
Old 12-01-2007, 05:45 PM   #2
RobinS
Guest
 
Posts: n/a
Default 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.
------------------------------
"Bill Angus" <mdangus@dont-spam-me.psychtest.com> wrote in message
news:%23XEep3mNHHA.2468@TK2MSFTNGP06.phx.gbl...
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


  Reply With Quote
Old 13-01-2007, 12:08 AM   #3
Bill Angus
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?

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.


  Reply With Quote
Old 13-01-2007, 12:30 AM   #4
RobinS
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?

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.
-----------------------------------
"Bill Angus" <mdangus@dont-spam-me.psychtest.com> wrote in message
news:eTv5CcqNHHA.3212@TK2MSFTNGP02.phx.gbl...
> 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.
>
>



  Reply With Quote
Old 14-01-2007, 08:49 PM   #5
Bill Angus
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?


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 ...

--
Thanks and have a great day!

Bill Angus, MA
http://www.psychtest.com


  Reply With Quote
Old 15-01-2007, 12:11 AM   #6
RobinS
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?


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.
----------------------------------------------



"Bill Angus" <mdangus@dont-spam-me.psychtest.com> wrote in message
news:eCnOh2BOHHA.1252@TK2MSFTNGP02.phx.gbl...
>
> 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 ...
>
> --
> Thanks and have a great day!
>
> Bill Angus, MA
> http://www.psychtest.com
>
>



  Reply With Quote
Old 15-01-2007, 11:52 PM   #7
Bill Angus
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?

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.
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:0OGdnbU2Br0mWzfYnZ2dnUVZ_qisnZ2d@comcast.com...
>
> 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.
> ----------------------------------------------
>
>
>
> "Bill Angus" <mdangus@dont-spam-me.psychtest.com> wrote in message
> news:eCnOh2BOHHA.1252@TK2MSFTNGP02.phx.gbl...
> >
> > 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 ...
> >
> > --
> > Thanks and have a great day!
> >
> > Bill Angus, MA
> > http://www.psychtest.com
> >
> >

>
>



  Reply With Quote
Old 16-01-2007, 06:08 AM   #8
RobinS
Guest
 
Posts: n/a
Default Re: Is .NET no good for some things?

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.
--------------------
"Bill Angus" <mdangus@nospam.psychtest.com> wrote in message
news:eIoY2AQOHHA.2232@TK2MSFTNGP02.phx.gbl...
> 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.
> "RobinS" <RobinS@NoSpam.yah.none> wrote in message
> news:0OGdnbU2Br0mWzfYnZ2dnUVZ_qisnZ2d@comcast.com...
>>
>> 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.
>> ----------------------------------------------
>>
>>
>>
>> "Bill Angus" <mdangus@dont-spam-me.psychtest.com> wrote in message
>> news:eCnOh2BOHHA.1252@TK2MSFTNGP02.phx.gbl...
>> >
>> > 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 ...
>> >
>> > --
>> > Thanks and have a great day!
>> >
>> > Bill Angus, MA
>> > http://www.psychtest.com
>> >
>> >

>>
>>

>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off