flat assembler
Message board for the users of flat assembler.

Index > Windows > Printing

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Hello all
I have been using Fasm for some time now and have become relatively good at getting around in it. I would like now to try printing from a program - but oh dear oh dear oh dear ...
I have read the topics here, I have looked at Iczelion, I have even looked at masm32, all with no success. Of course I have looked at Wn32Hlp but that doesn't gain many points for defining the terms it uses. I have done a series of Google searches on the subject, but none of them are of any great help - they either don't describe what they are doing or they just don't work (for me!)
I tried downloading Matt's rar but it wouldn't open - said there were errors in it.
Can anyone direct me to a straightforward program that just prints lines of text on a printer? If I get that far, I feel sure that I can flesh it out from that starting point.
Thanks in anticipation.
Post 06 Sep 2008, 09:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
In Windows, printing is quite similar as painting to the screen. You open a DC and starting drawing your output. Of course you have to select the desired printer before you can open the DC but there are helper functions for this. Have a look at PrintDlg.
Post 06 Sep 2008, 14:29
View user's profile Send private message Visit poster's website Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Thanks for your reply. I have only used GUI for the screen, never painting it.
Following Win32Hlp, I get as far as trying to define DOCINFO, but DOCINFO doesn't appear anywhere in my fasm directory. I have tried to set it up as a standard data definition, but then StartDoc returns error code 6, which presumably says it doesn't like it.
Post 06 Sep 2008, 22:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Error code 6: ERROR_INVALID_HANDLE

So the DC handle is not valid.
Post 07 Sep 2008, 00:18
View user's profile Send private message Visit poster's website Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Right, if you say so.
PrintDlg returns different values of pd.hDC every time I run it -
numbers such as 3572076 and even greater.
I do have pd.Flags set to PD_RETURNDC.
Post 07 Sep 2008, 05:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
You need to use the DC returned from CreateDC.
Post 07 Sep 2008, 05:33
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Crinan wrote:
I tried downloading Matt's rar but it wouldn't open - said there were errors in it.


Which rar file was that? I downloaded the Charles Petzold file and it opened fine for me. Is your Winrar extractor up to date? The Charles Petzold contains some printing examples in Chapters 13, 17.

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 07 Sep 2008, 05:38
View user's profile Send private message Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Reply to Revolution
I have been following the procedure in Win32hlp and it uses pd.hDC.
I quote:
Unlike a display DC, printer DCs are not owned by the window
management component, and they cannot be obtained by calling the
GetDC function. Instead, an application must call the CreateDC or PrintDlg
function. When an application calls CreateDC, it must supply a driver and
port name.

So I used PrintDlg because I don't know what the driver and port name are.

Reply to madmatt:
I have never used rar files before so I had just downloaded wrar38b5.exe
and your file was FASMW16726.rar

In the meantime, I have discovered fairly detailed examples of complete printing routines in masm32, so I might be able to convert these and use their logic. At least they are complete routines.
Thanks anyway.
Post 07 Sep 2008, 07:20
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 294
Alphonso
Is this any help to you?

A 'Hello Printer' program that uses the default printer. That's if I have understood Revolution correctly.
Code:
format PE GUI 4.0
include 'win32a.inc'

struct DOCINFO
        .cbSize         dd ?
        .lpszDocName    dd ?
        .lpszOutput     dd ?
        .lpszDatatype   dd ?
        .fwType         dd ?
ends

section '.code' code readable executable

        invoke  GetDefaultPrinter,PrinterName,PrinterNameSize   ;use GetProfileString for <w2k
        or      eax,eax
        jz      exit

        invoke  CreateDC,Driver,PrinterName,0,0
        or      eax,eax
        jz      exit
        mov     [hDC],eax
                                                                ;Maybe set up fonts etc..
        invoke  StartDoc,[hDC],Dinfo
        invoke  StartPage,[hDC]

        add     [PrinterNameSize],HelloLen-1                    ;Hello + name of printer
        invoke  TextOut,[hDC],100,100,Hello,[PrinterNameSize]   ;a 100,100 offset from top left corner of page

        invoke  EndPage,[hDC]
        invoke  EndDoc,[hDC]
        invoke  DeleteDC,[hDC]

exit:   invoke  ExitProcess,0

;-- ------------------------------------

section '.data' data readable writeable

        PrinterNameSize dd 256                                  ;Should work this out, see below
        hDC             dd ?
        Dinfo           DOCINFO 20,DocName,0,0,0
        DocName         db 'FasmDoc',0
        Driver          db 'WINSPOOL',0
        Hello           db 'Hello printer '
        HelloLen=$-Hello
        PrinterName     rb 256

;--------------------------------------

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          gdi,'GDI32.DLL',\
          winspool,'WINSPOOL.DRV'

  import kernel,\
         ExitProcess,'ExitProcess'

 import gdi,\
         CreateDC,'CreateDCA',\
         DeleteDC,'DeleteDC',\
         StartDoc,'StartDocA',\
         EndDoc,'EndDoc',\
         StartPage,'StartPage',\
         EndPage,'EndPage',\
         TextOut,'TextOutA'

 import winspool,\
        GetDefaultPrinter,'GetDefaultPrinterA'

;GetDefaultPrinter,NULL,PrinterNameSize will return number of bytes required for printer name    
Edit: - initialized DOCINFO, not set before but worked regardless !
Post 07 Sep 2008, 12:32
View user's profile Send private message Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Many thanks Alphonso
That's just the sort of thing I was hoping for.
I'll work along with that and see where I get to.
Thanks again.
Post 08 Sep 2008, 05:36
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
Crinan wrote:

Reply to madmatt:
I have never used rar files before so I had just downloaded wrar38b5.exe
and your file was FASMW16726.rar
Thanks anyway.


I'm using winrar 3.7, so looks like he changed the algorithm used in
compressing the files using the "best" method. In the next update,
I'll upload standard zip files using standard compression to try and prevent
problems like this. Oh, and thanks for informing about this problem. Smile
madmatt

_________________
Gimme a sledge hammer! I'LL FIX IT!
Post 08 Sep 2008, 14:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
I use 7-zip (google it). Supports rar, zip, bz2, etc. all in one program.
Post 08 Sep 2008, 14:41
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
and free! no winzip's evaluation delay dialogbox.

about printing.

on old hardware, or more standard printers, liek serial ones, it is exactlly as a typemachine.
you send a char via rs232 port
the printer will print it as is.
it naturally cares about tabs, CRLF, etc...

just hardware manufacturer decided to overcomplicate the process. making them very difficult to access without WINDOW$. Sad

how do you print a simple text with modern printers?
Post 08 Sep 2008, 16:17
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Oh yeah, thanks for reminding me edfed, 7-zip is completely free and open source.
Post 08 Sep 2008, 16:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
edfed wrote:
how do you print a simple text with modern printers?
The same way as with the older printers. Just open up the USB port and start sending plain text. The printer will print it just the same as before.

If you want graphics and colours then you need to format your data accordingly, just like before. Nothing has changed except for the COM--->USB connector thing.
Post 08 Sep 2008, 16:22
View user's profile Send private message Visit poster's website Reply with quote
farrier



Joined: 26 Aug 2004
Posts: 274
Location: North Central Mississippi
farrier
Quote:
how do you print a simple text with modern printers?


The program in the following link:

http://board.flatassembler.net/topic.php?p=70211#70211

can send raw text, printer control codes, PCL, ... to any printer on your computer or network. What it doesn't do, is handle all the nice things the windows does for you when you want to print in different font or formats or orientations unless you know the commands that your printer requires to do these things, and you send these commands yourself.

hth,

farrier

_________________
Some Assembly Required
It's a good day to code!
U.S.Constitution; Bill of Rights; Amendment 1:
... the right of the people peaceably to assemble, ...
The code is dark, and full of errors!
Post 09 Sep 2008, 01:14
View user's profile Send private message Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Sometimes things just don't work out.
I'm sure I was holding my mouth right too.
About 7-zip:
I downloaded jZip v1.3.0.54552 from the 7-zip site and tried to extract FASMW16726.rar:
"Jzip does not support the file format of the file you are trying to open"

About your program Alphonso:
I compiled it and it worked (of course!)
I then tried to include an invoke to MessageBox.
I thought I should include USER32.DLL in the library statement, but this caused the following error
library kenel,'KERNEL32.DLL',/
\Fasm\Include\macro/import32.inc[7]library[2]:
if defined name##.redundant
error: extra characters on line.
Funny, but if I omit "winspool,'WINSPOOL.DRV'" it is ok.
I don't understand libraries and library calls, and the manual seems to be written for people who already understand the concepts (not a criticism) so I don't know what this means and how to get over it.

As far as I can see, USER32 contains all the calls(?) that I would like to use, but how this affects KERNEL32 ...
Up to now I have just used the .end macro and this worked fine for all I wanted to do. I tried writing my own version of the .end macro but this had the same effect.
Can you see what I am doing wrong and how to overcome it?
Post 09 Sep 2008, 05:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Jzip, WTF Question Did you really find that at http://www.7-zip.org/?
Post 09 Sep 2008, 06:20
View user's profile Send private message Visit poster's website Reply with quote
Crinan



Joined: 05 Dec 2006
Posts: 28
Location: New Zealand
Crinan
Yes, that's where I downloaded jZipV1c.exe from, about 2 hours ago.
Post 09 Sep 2008, 07:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17641
Location: In your JS exploiting you and your system
revolution
Just you use 7-Zip Version 4.something. That works perfectly fine for me and is what I recommended.

If jZip doesn't work then delete it and forget about it.

BTW: I still can't see any reference to jZip on the 7-zip site Exclamation
Post 09 Sep 2008, 07:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.