Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purging the jobs in Winspool #661

Closed
badarolp opened this issue May 20, 2016 · 7 comments · Fixed by #1556
Closed

Purging the jobs in Winspool #661

badarolp opened this issue May 20, 2016 · 7 comments · Fixed by #1556

Comments

@badarolp
Copy link

To purge the jobs in the spool you have to make a Winspool.SetPrinter with PRINTER_CONTROL_PURGE, but there is no such method in JNA.

Can I implement that? Is there other way to clean up my printer spooler?

@wolftobias
Copy link
Contributor

Have you seen this example?

https://github.com/java-native-access/jna/blob/master/contrib/w32printing/src/com/sun/jna/platform/win32/Win32SpoolMonitor.java

@badarolp
Copy link
Author

Yes, i saw it. But it's just a status monitor of the spooler.
For now I'am calling a .exe c++ program that clean's the spooler for me, but it's not so elegant...

@matthiasblaesing
Copy link
Member

I think this is perfectly doable - you'll have to wire up the necessary parts in Winspool.java:

https://github.com/java-native-access/jna/blob/master/contrib/platform/src/com/sun/jna/platform/win32/Winspool.java

The documentation is in MSDN:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145082%28v=vs.85%29.aspx

A few of the PRINTER_INFO structures are already bound, so they can be used as a basis. The constants for the commands need to be added as contants to the interface (PRINTER_CONTROL_*)

@badarolp
Copy link
Author

Thanks @matthiasblaesing, I will try this.

@wolftobias
Copy link
Contributor

wolftobias commented Nov 1, 2019 via email

@tresf
Copy link
Contributor

tresf commented Oct 23, 2023

Hi, plan on adding the SetJob to Winspool. I will submit a PR soon.

I noticed that some constants in Winspool are of type short whereas others are of type int. This addition requires adding something like this:

    public static final short JOB_CONTROL_PAUSE = 0x01;
    public static final short JOB_CONTROL_RESUME = 0x02;
    // ... 0x03, etc... 

I believe the Win32 API defines most of these as DWORDS, but I'm having a hard time finding out which one JNA should be using, quoting Winspool.java:

// int
public static final short PRINTER_NOTIFY_FIELD_SERVER_NAME = 0x00;
// short
public static final short JOB_NOTIFY_FIELD_PRINTER_NAME = 0x00;

Which should the PR use? Perhaps a better question is, how should I know this for future PRs? Thanks in advance.

@matthiasblaesing
Copy link
Member

If a constant is only used "as is" and the use sites are declared as short, than it makes sense to use short in the constant definition. In this case the two short examples are used in PRINTER_NOTIFY_INFO_DATA.Type, from my quick read the value is only used there. Using an int for the constant would mean, that a cast is necessary when setting type.

This is different when the constants define discreet values of a bitfield. In that case it is highly probable that you will "or" the values together and you'll need a cast anyway.

For JOB_CONTROL* I don't see a reason to make them short. The use site is the only type indicator and a DWORD is indeed best mapped to int.

mstyura pushed a commit to mstyura/jna that referenced this issue Sep 9, 2024
…s#661)

Motivation:

QuicheQuicConnection does only need native memory for one recipient
addres, while we allocated memory for two.

Modifications:

Only allocate native memory for one address

Result:

Less native memory usage per quic connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants