WinSpool and EnumJobs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

WinSpool and EnumJobs

Carl Gundel-2
Does anyone here have an implementation of EnumJobs that they can share?

Thanks!

-Carl Gundel

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

AW: WinSpool and EnumJobs

Möbus. Manfred
Hi Carl,
haven't got such an implementation, but consulting MSDN it does not look too complicated, like many of similar enum functions it should work as follows (just a rough sketch)

|rc pBytesNeeded pNumJobs buffer addr jobInfo |
rc := WinSpoolDLL current enumJobs: handle
                first: 0 number: 100 level: 1
                buffer: null cbBuffer: 0
                pcbNeeded: pBytesNeeded asParameter pcReturned: pNumJobs asParameter.
(self lastOsError =  ErrorInsufficientBuffer) ifTrue: [
    addr := ExternalAddress allocateMemory: pBytesNeeded asInteger.
    buffer := WinJobInfo1 atAddress: addr.
    rc := WinSpoolDLL current enumJobs: handle
                first: 0 number: 100 level: 1
                buffer: buffer cbBuffer: addr memorySize
                pcbNeeded: pBytesNeeded asParameter pcReturned: pNumJobs asParameter.
    rc ifTrue: [
        1 to: pNumJobs asInteger do: [ :i |
            jobInfo := WinJobInfo1 atAddress:
                        (ExternalAddress fromInteger: addr asInteger + ((i - 1) * WinJobInfo1 sizeInBytes).
            Transcript nextPutAll: (String atAddress: (ExternalAddress fromInteger: jobInfo pDocument)); cr ].].
    addr release. ].


And the function in winspool-dll is something like
enumJobs: hPrinter first: f number: nJob level: l buffer: p cbBuff: cb pcbNeeded: n pcReturned: r

        <api: EnumJobsA ulong ulong ulong ulong struct ulong struct struct boolean>
        ^self invalidArgument

Just be sure that you pass the "buffer" parameter properly, as address explicitly allocated on external memory, because it does not only contain the resulting jobinfo structs, but appended the characters of strings used in these structs (like printerName), so if you would simply pass a ByteArray as "struct", the vm would copy it to some internal location, call the dll function, and copy the data back. The pointers to strings in the resulting jobInfo structs then point to this internal location which by now probably contains other contents.

Hope this helps you along
Manfred


-----Ursprüngliche Nachricht-----
Von: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] Im Auftrag von Carl Gundel
Gesendet: Dienstag, 18. September 2012 16:50
An: [hidden email]
Betreff: WinSpool and EnumJobs

Does anyone here have an implementation of EnumJobs that they can share?

Thanks!

-Carl Gundel

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
________________________________

Treffen Sie AEB vom 17.-19. Oktober 2012 auf dem 29. Deutschen Logistik-Kongress in Berlin.
Weitere Informationen und Termin-Vereinbarung unter: www.aeb.de/dlk

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Hung process after vmInterrupt: ??

Carl Gundel-3
Hey all!  Happy New Year!

I seem to have a process that hung when a vmInterrupt: message was sent.
Here is the stack trace.  How does this happen?  Is it a bug in VSE?

ProcessScheduler>>suspendActive
ProcessScheduler>>yield
ProcessScheduler>>resume: <aProcess>
Semaphore>>signal
Process class>>osEventInterruptGui
Process class>>osEventInterrupt
Process class(Object)>>perform: <#osEventInterrupt>
ReadStream(Object)vmInterrupt: <#osEventInterrupt>
ReadStream(Stream)>>position: <32>
ReadStream(Stream)>>backupOver: <aCharacter>
ReadStream(Stream)>>peek
String>>asArrayOfSubstrings: <aCharacter>
Font class>>fromCommaDelimited: <'Times New Roman,10, false,false...'>
OSFont(Font)>>asNormalFont
WordProcessor>>setNormal
[] in WordProcessor>>typeReportFieldsFor:on:x:y:

Any ideas?  Why should my process just stop running when it doesn't throw an
exception?

Thanks,

-Carl Gundel

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Hung process after vmInterrupt: ??

Andreas Rosenberg
Hi Carl,

happy new year to you, too!

I think your problem has nothing to do with #vmInterrupt:
The #osEventInterrupt code only triggers the ProcessScheduler.

Something must be wrong with the processes in your image.
The Smalltalk process scheduler does not assign CPU time to
all processes. Only the process with the highest priority gets
CPU time. All other processes will stay suspended, until processes
with higher priority have completed their work.

Usually you have an idle process, that does only loop in
ProcessScheduler>>idleLoop  

Then you got the UserInterfaceProcess that does loop in
NotificationManager>>runEventLoop

The user interface process will be waiting at the OSEventSemaphore
if no code is running. This will cause the idle process to get active.

The idle process loop will call UserLibrary waitMessage. So if no
user activity and nothing else is running the OS process will
wait for any windows messages.

If any windows message arrives #waitMessage will return. This signals
the OSEventSemaphore and lets the user interface process resume its
work.

If your UserInterface process runs for a longer time and windows messages
will arrive, you current process will be interrupted. That's the state
visible in your stack trace. Now it seems the process scheduler found
a process with higher priority than your current process.
That higher priority process will be activated and it will run until
it terminates. If it does not terminate or suspend itself, other
processes will never get resumed.

Hopefully this explanation will help you.

Best regards,
 Andreas

Andreas Rosenberg | eMail: [hidden email]
APIS GmbH         | Phone: +49 9482 9415-0
Im Haslet 42      | Fax: +49 9482 9415-55
93086 Worth/D     | WWW: <http://www.apis.de/>
Germany           | <http://www.fmea.de/>




-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]]On Behalf Of Carl Gundel
Sent: Donnerstag, 3. Januar 2013 18:22
To: [hidden email]
Subject: Hung process after vmInterrupt: ??


Hey all!  Happy New Year!

I seem to have a process that hung when a vmInterrupt: message was sent.
Here is the stack trace.  How does this happen?  Is it a bug in VSE?

ProcessScheduler>>suspendActive
ProcessScheduler>>yield
ProcessScheduler>>resume: <aProcess>
Semaphore>>signal
Process class>>osEventInterruptGui
Process class>>osEventInterrupt
Process class(Object)>>perform: <#osEventInterrupt>
ReadStream(Object)vmInterrupt: <#osEventInterrupt>
ReadStream(Stream)>>position: <32>
ReadStream(Stream)>>backupOver: <aCharacter>
ReadStream(Stream)>>peek
String>>asArrayOfSubstrings: <aCharacter>
Font class>>fromCommaDelimited: <'Times New Roman,10, false,false...'>
OSFont(Font)>>asNormalFont
WordProcessor>>setNormal
[] in WordProcessor>>typeReportFieldsFor:on:x:y:

Any ideas?  Why should my process just stop running when it doesn't throw an
exception?

Thanks,

-Carl Gundel

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Hung process after vmInterrupt: ??

Carl Gundel-3
Thanks Andreas.  I thought it might have been as you explained, but I wasn't
sure.  I don't see any other processes that should be preventing that one
from running, so I'm a little stumped.

-Carl

-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]] On Behalf Of Andreas Rosenberg
Sent: Friday, January 04, 2013 4:46 AM
To: [hidden email]
Subject: Re: Hung process after vmInterrupt: ??

Hi Carl,

happy new year to you, too!

I think your problem has nothing to do with #vmInterrupt:
The #osEventInterrupt code only triggers the ProcessScheduler.

Something must be wrong with the processes in your image.
The Smalltalk process scheduler does not assign CPU time to all processes.
Only the process with the highest priority gets CPU time. All other
processes will stay suspended, until processes with higher priority have
completed their work.

Usually you have an idle process, that does only loop in
ProcessScheduler>>idleLoop

Then you got the UserInterfaceProcess that does loop in
NotificationManager>>runEventLoop

The user interface process will be waiting at the OSEventSemaphore if no
code is running. This will cause the idle process to get active.

The idle process loop will call UserLibrary waitMessage. So if no user
activity and nothing else is running the OS process will wait for any
windows messages.

If any windows message arrives #waitMessage will return. This signals the
OSEventSemaphore and lets the user interface process resume its work.

If your UserInterface process runs for a longer time and windows messages
will arrive, you current process will be interrupted. That's the state
visible in your stack trace. Now it seems the process scheduler found a
process with higher priority than your current process.
That higher priority process will be activated and it will run until it
terminates. If it does not terminate or suspend itself, other processes will
never get resumed.

Hopefully this explanation will help you.

Best regards,
 Andreas

Andreas Rosenberg | eMail: [hidden email]
APIS GmbH         | Phone: +49 9482 9415-0
Im Haslet 42      | Fax: +49 9482 9415-55
93086 Worth/D     | WWW: <http://www.apis.de/>
Germany           | <http://www.fmea.de/>




-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]]On Behalf Of Carl Gundel
Sent: Donnerstag, 3. Januar 2013 18:22
To: [hidden email]
Subject: Hung process after vmInterrupt: ??


Hey all!  Happy New Year!

I seem to have a process that hung when a vmInterrupt: message was sent.
Here is the stack trace.  How does this happen?  Is it a bug in VSE?

ProcessScheduler>>suspendActive
ProcessScheduler>>yield
ProcessScheduler>>resume: <aProcess>
Semaphore>>signal
Process class>>osEventInterruptGui
Process class>>osEventInterrupt
Process class(Object)>>perform: <#osEventInterrupt>
ReadStream(Object)vmInterrupt: <#osEventInterrupt>
ReadStream(Stream)>>position: <32>
ReadStream(Stream)>>backupOver: <aCharacter> ReadStream(Stream)>>peek
String>>asArrayOfSubstrings: <aCharacter>
Font class>>fromCommaDelimited: <'Times New Roman,10, false,false...'>
OSFont(Font)>>asNormalFont
WordProcessor>>setNormal
[] in WordProcessor>>typeReportFieldsFor:on:x:y:

Any ideas?  Why should my process just stop running when it doesn't throw an
exception?

Thanks,

-Carl Gundel

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

How to programmatically set the printer to landscape orientation?

Carl Gundel-3
In reply to this post by Möbus. Manfred
How can I set landscape mode programmatically?  I try to set the
dmOrientation value to 2 in the DEVMODE struct, but it still prints in
portrait orientation.

Should be easy.  Any ideas?

Thanks,

-Carl

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: How to programmatically set the printer to landscape orientation?

Carsten Schenke
Hello,

you also have to set the mask flag DmOrientation (1) in dmFields.
You should be able to change the mode then using the API:
ResetDCA (maybe not implemented)
with the parameters device context (of the printer)
and the DEVMODE structure.
After this you should update the extent (using the initExtent method).

    Carsten

----- Original Message -----
From: "Carl Gundel" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, January 10, 2013 11:31 PM
Subject: How to programmatically set the printer to landscape orientation?


> How can I set landscape mode programmatically?  I try to set the
> dmOrientation value to 2 in the DEVMODE struct, but it still prints in
> portrait orientation.
>
> Should be easy.  Any ideas?
>
> Thanks,
>
> -Carl
>
> ***           this signature added by listserv             ***
> *** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
> *** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***