-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add missing PRINTER_INFO_X structs #1429
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
e842ac9
7880ff3
a816862
399136d
820eb7f
eefe7de
b8caf8b
8e87b13
ac29f71
9ed81f6
5e2551d
f68bb7b
9c126f0
0477646
eeda6e0
f58508a
9581b69
f84d022
77c9711
f50ca82
7d6879f
05c8f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,18 +28,97 @@ | |
import com.sun.jna.Structure; | ||
import com.sun.jna.Structure.FieldOrder; | ||
import com.sun.jna.platform.win32.WinNT.HANDLE; | ||
import com.sun.jna.platform.win32.WinDef.HBITMAP; | ||
import com.sun.jna.platform.win32.WinDef.RECT; | ||
import com.sun.jna.Union; | ||
|
||
import static com.sun.jna.platform.win32.WinDef.*; | ||
|
||
/** | ||
* Ported from WinGDI.h. | ||
* Microsoft Windows SDK 6.0A. | ||
* @author dblock[at]dblock.org | ||
* @author Andreas "PAX" Lück, onkelpax-git[at]yahoo.de | ||
* @author SSHTOOLS Limited, support@sshtools.com | ||
*/ | ||
public interface WinGDI { | ||
int RDH_RECTANGLES = 1; | ||
|
||
@FieldOrder({ "dmDeviceName", "dmSpecVersion", "dmDriverVersion", "dmSize", "dmDriverExtra", "dmFields", "dmUnion1", "dmColor", | ||
"dmDuplex", "dmYResolution", "dmTTOption", "dmCollate", "dmFormName", "dmLogPixels", "dmBitsPerPel", "dmPelsWidth", | ||
"dmPelsHeight", "dummyunionname2", "dmDisplayFrequency", "dmICMMethod", "dmICMIntent", "dmMediaType", "dmDitherType", | ||
"dmReserved1", "dmReserved2", "dmPanningWidth", "dmPanningHeight" }) | ||
|
||
public static class DEVMODE extends Structure { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reopening this comment, since the previous one at this code marking ended up talking about fixing the pointer and then reading a wide string properly. Quoting @dbwiddis:
@dbwiddis Is the current structure OK? My structure is a copy from a project called "damage" and it seems to mirror the Microsoft definition exactly, take note of the words There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd quibble over style; I'd prefer to see all the structure fields together at the top, and the nested class definitions below them. Right now it's hard to see which elements are in the union. Yes, it's fine to match the Windows API names. There is one missing piece, though, and I'm not clear how the structure works. In the native, all fields of the union are essentially "active" at any given time. In JNA, we only "read" the member of the union which is declared to be the correct type. For most unions this information is given in one of the other fields. In this structure it looks like one of the fields is a bitmask indicating which of several union fields may be active. So you might have to do some bit manipulation there, or perhaps just read all three possibilities, doing something like this in the @Override
public void read() {
super.read();
dmUnion1.setType(DUMMYSTRUCTNAME.class);
dmUnion1.read();
dmUnion1.setType(POINT.class);
dmUnion1.read();
dmUnion1.setType(DUMMYSTRUCTNAME2.class);
dmUnion1.read();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dbwiddis thanks. I've taken a deep dive into For starters, I've placed JavaDoc comments into the Structure explaining exactly when a field is used, so this PR has a lot more DEVMODE information in it now. I've also moved the fields around, I hope they're to your liking. :)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First ... not sure what you're doing with the To me it looks like It looks to me like you could use the @Override
public void read() {
super.read();
if (dmFields & (DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH
| DM_PAPERWIDTH | DM_SCALE | DM_COPIES | DM_DEFAULTSOURC
| DM_PRINTQUALITY) > 0) {
dmUnion1.setType(DUMMYSTRUCTNAME.class);
dmUnion1.read();
}
if (dmFields & (DM_POSITION) > 0) {
dmUnion1.setType(POINT.class);
dmUnion1.read();
}
if (dmFields & (DM_POSITION | DM_DISPLAYORIENTATION | DM_DISPLAYFIXEDOUTPUT) > 0) {
dmUnion1.setType(DUMMYSTRUCTNAME2.class);
dmUnion1.read();
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading more it does look like there are different versions of the structure, thus the different version numbers and size fields available. I'm guessing the newer version(s) added/would add fields at the end. So if the size is smaller than So this falls into a typical Windows API situation of "call once to get the size and then call again with the properly sized buffer" pattern. |
||
public byte[] dmDeviceName = new byte[Winspool.CCHDEVICENAME]; | ||
tresf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public WORD dmSpecVersion; | ||
tresf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public WORD dmDriverVersion; | ||
public WORD dmSize; | ||
public WORD dmDriverExtra; | ||
public DWORD dmFields; | ||
public DUMMYUNIONNAME dmUnion1; | ||
|
||
public static class DUMMYUNIONNAME extends Union { | ||
public DUMMYSTRUCTNAME dummystructname; | ||
|
||
@FieldOrder({ "dmOrientation", "dmPaperSize", "dmPaperLength", "dmPaperWidth", "dmScale", "dmCopies", "dmDefaultSource", | ||
"dmPrintQuality" }) | ||
public static class DUMMYSTRUCTNAME extends Structure { | ||
tresf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public short dmOrientation; | ||
public short dmPaperSize; | ||
public short dmPaperLength; | ||
public short dmPaperWidth; | ||
public short dmScale; | ||
public short dmCopies; | ||
public short dmDefaultSource; | ||
public short dmPrintQuality; | ||
|
||
public DUMMYSTRUCTNAME() { | ||
super(); | ||
} | ||
} | ||
|
||
public POINT dmPosition; | ||
public DUMMYSTRUCTNAME2 dummystructname2; | ||
|
||
@FieldOrder({ "dmPosition", "dmDisplayOrientation", "dmDisplayFixedOutput" }) | ||
public static class DUMMYSTRUCTNAME2 extends Structure { | ||
public POINT dmPosition; | ||
public DWORD dmDisplayOrientation; | ||
public DWORD dmDisplayFixedOutput; | ||
|
||
public DUMMYSTRUCTNAME2() { | ||
super(); | ||
} | ||
} | ||
} | ||
|
||
public short dmColor; | ||
public short dmDuplex; | ||
public short dmYResolution; | ||
public short dmTTOption; | ||
public short dmCollate; | ||
public byte[] dmFormName = new byte[Winspool.CCHFORMNAME]; | ||
public WORD dmLogPixels; | ||
public DWORD dmBitsPerPel; | ||
public DWORD dmPelsWidth; | ||
public DWORD dmPelsHeight; | ||
public DUMMYUNIONNAME2 dummyunionname2; | ||
|
||
public static class DUMMYUNIONNAME2 extends Union { | ||
public DWORD dmDisplayFlags; | ||
public DWORD dmNup; | ||
} | ||
|
||
public DWORD dmDisplayFrequency; | ||
public DWORD dmICMMethod; | ||
public DWORD dmICMIntent; | ||
public DWORD dmMediaType; | ||
public DWORD dmDitherType; | ||
public DWORD dmReserved1; | ||
public DWORD dmReserved2; | ||
public DWORD dmPanningWidth; | ||
public DWORD dmPanningHeight; | ||
} | ||
|
||
@FieldOrder({"dwSize", "iType", "nCount", "nRgnSize", "rcBound"}) | ||
class RGNDATAHEADER extends Structure { | ||
public int dwSize = size(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import com.sun.jna.Structure; | ||
import com.sun.jna.Structure.FieldOrder; | ||
import com.sun.jna.Union; | ||
import com.sun.jna.platform.win32.WinGDI.DEVMODE; | ||
import com.sun.jna.platform.win32.WinBase.SYSTEMTIME; | ||
import com.sun.jna.platform.win32.WinDef.DWORD; | ||
import com.sun.jna.platform.win32.WinDef.DWORDByReference; | ||
|
@@ -41,6 +42,8 @@ | |
import com.sun.jna.win32.StdCallLibrary; | ||
import com.sun.jna.win32.W32APIOptions; | ||
|
||
import static com.sun.jna.platform.win32.WinDef.*; | ||
|
||
/** | ||
* Ported from Winspool.h. Windows SDK 6.0a | ||
* | ||
|
@@ -51,6 +54,7 @@ public interface Winspool extends StdCallLibrary { | |
Winspool INSTANCE = Native.load("Winspool.drv", Winspool.class, W32APIOptions.DEFAULT_OPTIONS); | ||
|
||
public static final int CCHDEVICENAME = 32; | ||
public static final int CCHFORMNAME = 32; | ||
|
||
public static final int PRINTER_STATUS_PAUSED = 0x00000001; | ||
public static final int PRINTER_STATUS_ERROR = 0x00000002; | ||
|
@@ -508,6 +512,20 @@ public boolean hasAttribute(int value) { | |
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_3 structure specifies printer security information. | ||
*/ | ||
@FieldOrder({"pSecurityDescriptor"}) | ||
public static class PRINTER_INFO_3 extends Structure { | ||
public WinNT.SECURITY_DESCRIPTOR_RELATIVE pSecurityDescriptor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although Fortunately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pointer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reopening... so going back on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue occurs for I can update Alternately I can switch I tried to convert the // Doesn't work :(
public DEVMODE(Pointer p) {
super(p);
ensureAllocated();
read();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My apologies, I answered the first one thinking about a completely different recent change. Ultimately you need to map a pointer of some sort, and then use that pointer to map to the structure it points to. Using the Don't change old ones to break compatibility. If you want consistency, feel free to match them, but
I think the structure (by reference) is the easiest. So you get FooStructure(Pointer p) {
super(p);
// anything else you need to do
} |
||
|
||
public PRINTER_INFO_3() {} | ||
|
||
public PRINTER_INFO_3(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_4 structure specifies general printer information. | ||
* <p> | ||
|
@@ -546,6 +564,81 @@ public PRINTER_INFO_4(int size) { | |
} | ||
} | ||
|
||
/** | ||
tresf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* The PRINTER_INFO_5 structure specifies detailed printer information. | ||
*/ | ||
@FieldOrder({"pPrinterName", "pPortName", "Attributes", "DeviceNotSelectedTimeout", "TransmissionRetryTimeout" }) | ||
public static class PRINTER_INFO_5 extends Structure { | ||
public String pPrinterName; | ||
public String pPortName; | ||
public DWORD Attributes; | ||
public DWORD DeviceNotSelectedTimeout; | ||
public DWORD TransmissionRetryTimeout; | ||
|
||
public PRINTER_INFO_5() {} | ||
|
||
public PRINTER_INFO_5(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_6 structure specifies the status value of a printer. | ||
*/ | ||
@FieldOrder({"dwStatus"}) | ||
public static class PRINTER_INFO_6 extends Structure { | ||
public DWORD dwStatus; | ||
|
||
public PRINTER_INFO_6() {} | ||
|
||
public PRINTER_INFO_6(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_7 structure specifies directory services printer information. | ||
*/ | ||
@FieldOrder({"pszObjectGUID", "dwAction"}) | ||
public static class PRINTER_INFO_7 extends Structure { | ||
public String pszObjectGUID; | ||
public DWORD dwAction; | ||
|
||
public PRINTER_INFO_7() {} | ||
|
||
public PRINTER_INFO_7(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_8 structure specifies the global default printer settings. | ||
*/ | ||
@FieldOrder({"pDevMode"}) | ||
public static class PRINTER_INFO_8 extends Structure { | ||
public DEVMODE pDevMode; | ||
|
||
public PRINTER_INFO_8() {} | ||
|
||
public PRINTER_INFO_8(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_INFO_9 structure specifies the per-user default printer settings. | ||
*/ | ||
@FieldOrder({"pDevMode"}) | ||
public static class PRINTER_INFO_9 extends Structure { | ||
public DEVMODE pDevMode; | ||
|
||
public PRINTER_INFO_9() {} | ||
|
||
public PRINTER_INFO_9(int size) { | ||
super(new Memory((long)size)); | ||
} | ||
} | ||
|
||
/** | ||
* The PRINTER_DEFAULTS structure specifies the default data type, | ||
* environment, initialization data, and access rights for a printer. | ||
|
Uh oh!
There was an error while loading. Please reload this page.