News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Optimized Printing Question

Started by z941998, November 11, 2009, 04:33:19 AM

Previous topic - Next topic

z941998

Hi all,

I was reviewing the SDK for printing.  I used the provided examples and created some simple tests to do some more learning.

The attached coding is what I currently have.  The coding runs everything just fine up to the OpenPrinter statement, then it fails with invalid printer name, even thou I verified via a messagebox it is there and correct just before the OpenPrinter statement.  Not sure what to do, any thoughts.

Also, how do I convert the OOC format Graphics* graphics statement to asm format and its associated methods.

Thanks
Steve

MichaelW

I can't see any problem with your code, but my test app running under Window 2000 works OK.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
    include \masm32\include\winspool.inc
    includelib \masm32\lib\winspool.lib
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        hPrinter dd 0
        cbBuffer dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke GetDefaultPrinter, NULL, ADDR cbBuffer
    print str$(eax),13,10
    print str$(cbBuffer),13,10

    mov ebx, alloc(cbBuffer)

    invoke GetDefaultPrinter, ebx, ADDR cbBuffer
    print str$(eax),13,10
    print ebx,13,10

    invoke OpenPrinter, ebx, ADDR hPrinter, NULL
    print str$(eax),13,10
    print hex$(hPrinter),13,10

    invoke ClosePrinter, hPrinter
    print str$(eax),13,10

    free ebx

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


0
17
1
HP DeskJet 1000C
1
001352F4
1

eschew obfuscation

z941998

Sir Michael,

I cut and pasted your example code and did all the normal compile stuff.  Everything worked as defined.  OS = XP SP2.

I am still testing what I have just to make sure I am on the right path and to understand what I am doing wrong.

Thanks Steve

herge

 Hi MichaelW:

When I run the progran we get a message winspool.dll was not found and re-install may fix
this problem.
I have a winspool.drv and a winspool.exe in c:\windows\system32

04/14/2008  05:42 AM           146,432 winspool.drv
08/04/2004  07:00 AM             2,112 winspool.exe
               2 File(s)        148,544 bytes
               0 Dir(s)  119,351,197,696 bytes free

Regards: herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

z941998

Micheal and Herge,

I found two issues:

First memory allocation is working (ie allocated) but for some reason random data was showing up in-between commands within the allocated area itself. Still not sure why.  I then used a Local variable and defined it as a 256 byte array and referred to this versus the allocated area.  This took care of this issued, although I still need to go back and find out why data is showing up randomly in an allocated area.

Second, I also expanded some useage of the Win Spooler (added and used more functions).  After tracing thru a couple or errors, I found out that I have about 50 different versions through-out my system (different Dos dates).  The one I used with my app below was at least 10 versions back, so I referred my coding to use the one within the Windows directory and retested.  Every thing worked fine.

I have learned to added coding to check for version control during setup of my apps, to avoid this issue.  Others should also take note.

Thanks
Steve


farrier

Quote from: herge on November 20, 2009, 12:37:38 PM
When I run the progran we get a message winspool.dll was not found and re-install may fix
this problem.
I have a winspool.drv and a winspool.exe in c:\windows\system32

Regards: herge

I think all OS's considered NT variant, have .dll version.  In my PrintRTF code I use the following for use with 9x OS's an beyond...
.data
szWinSpoolDRV DB "Winspool.drv", 0
szWinSpoolDLL DB "Winspool.dll", 0
szOpenPrinterA db 'OpenPrinterA', 0


.code
invoke LoadLibrary, offset szWinSpoolDLL ;NT
or eax, eax
jnz @F
invoke LoadLibrary, offset szWinSpoolDRV ;Win9x
@@: mov hSpoolLib, eax

invoke GetProcAddress, hSpoolLib, offset szOpenPrinterA
...


hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

z941998

Thanks Farrier, I like the dual OS capability and will convert / insert this method into my coding also. Steve