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

Win32 Console API: GetStdHandle, WriteConsole, GetCurrentConsoleFont #251

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/CfgMgr32.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.sun.jna.platform.win32;

/**
* Cfgmgr32.dll Interface.
*
* @author Luke Quinane
*/
public interface CfgMgr32 {
int CR_SUCCESS = 0x00000000;
int CR_DEFAULT = 0x00000001;
int CR_OUT_OF_MEMORY = 0x00000002;
int CR_INVALID_POINTER = 0x00000003;
int CR_INVALID_FLAG = 0x00000004;
int CR_INVALID_DEVNODE = 0x00000005;
int CR_INVALID_DEVINST = CR_INVALID_DEVNODE;
int CR_INVALID_RES_DES = 0x00000006;
int CR_INVALID_LOG_CONF = 0x00000007;
int CR_INVALID_ARBITRATOR = 0x00000008;
int CR_INVALID_NODELIST = 0x00000009;
int CR_DEVNODE_HAS_REQS = 0x0000000A;
int CR_DEVINST_HAS_REQS = CR_DEVNODE_HAS_REQS;
int CR_INVALID_RESOURCEID = 0x0000000B;
int CR_DLVXD_NOT_FOUND = 0x0000000C;
int CR_NO_SUCH_DEVNODE = 0x0000000D;
int CR_NO_SUCH_DEVINST = CR_NO_SUCH_DEVNODE;
int CR_NO_MORE_LOG_CONF = 0x0000000E;
int CR_NO_MORE_RES_DES = 0x0000000F;
int CR_ALREADY_SUCH_DEVNODE = 0x00000010;
int CR_ALREADY_SUCH_DEVINST = CR_ALREADY_SUCH_DEVNODE;
int CR_INVALID_RANGE_LIST = 0x00000011;
int CR_INVALID_RANGE = 0x00000012;
int CR_FAILURE = 0x00000013;
int CR_NO_SUCH_LOGICAL_DEV = 0x00000014;
int CR_CREATE_BLOCKED = 0x00000015;
int CR_NOT_SYSTEM_VM = 0x00000016;
int CR_REMOVE_VETOED = 0x00000017;
int CR_APM_VETOED = 0x00000018;
int CR_INVALID_LOAD_TYPE = 0x00000019;
int CR_BUFFER_SMALL = 0x0000001A;
int CR_NO_ARBITRATOR = 0x0000001B;
int CR_NO_REGISTRY_HANDLE = 0x0000001C;
int CR_REGISTRY_ERROR = 0x0000001D;
int CR_INVALID_DEVICE_ID = 0x0000001E;
int CR_INVALID_DATA = 0x0000001F;
int CR_INVALID_API = 0x00000020;
int CR_DEVLOADER_NOT_READY = 0x00000021;
int CR_NEED_RESTART = 0x00000022;
int CR_NO_MORE_HW_PROFILES = 0x00000023;
int CR_DEVICE_NOT_THERE = 0x00000024;
int CR_NO_SUCH_VALUE = 0x00000025;
int CR_WRONG_TYPE = 0x00000026;
int CR_INVALID_PRIORITY = 0x00000027;
int CR_NOT_DISABLEABLE = 0x00000028;
int CR_FREE_RESOURCES = 0x00000029;
int CR_QUERY_VETOED = 0x0000002A;
int CR_CANT_SHARE_IRQ = 0x0000002B;
int CR_NO_DEPENDENT = 0x0000002C;
int CR_SAME_RESOURCES = 0x0000002D;
int CR_NO_SUCH_REGISTRY_KEY = 0x0000002E;
int CR_INVALID_MACHINENAME = 0x0000002F;
int CR_REMOTE_COMM_FAILURE = 0x00000030;
int CR_MACHINE_UNAVAILABLE = 0x00000031;
int CR_NO_CM_SERVICES = 0x00000032;
int CR_ACCESS_DENIED = 0x00000033;
int CR_CALL_NOT_IMPLEMENTED = 0x00000034;
int CR_INVALID_PROPERTY = 0x00000035;
int CR_DEVICE_INTERFACE_ACTIVE = 0x00000036;
int CR_NO_SUCH_DEVICE_INTERFACE = 0x00000037;
int CR_INVALID_REFERENCE_STRING = 0x00000038;
int CR_INVALID_CONFLICT_LIST = 0x00000039;
int CR_INVALID_INDEX = 0x0000003A;
int CR_INVALID_STRUCTURE_SIZE = 0x0000003B;
int NUM_CR_RESULTS = 0x0000003C;
}
67 changes: 67 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/Ntddk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.sun.jna.platform.win32;

/**
* The interface for the Ntddk.h constants.
*
* @author Luke Quinane
*/
public class Ntddk {
public static final int FILE_DEVICE_8042_PORT = 0x00000027;
public static final int FILE_DEVICE_ACPI = 0x00000032;
public static final int FILE_DEVICE_BATTERY = 0x00000029;
public static final int FILE_DEVICE_BEEP = 0x00000001;
public static final int FILE_DEVICE_BUS_EXTENDER = 0x0000002a;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This should be an interface (as indicated also by the Javadoc)
  • Please drop the public static final as this is the default for interfaces

public static final int FILE_DEVICE_CD_ROM = 0x00000002;
public static final int FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003;
public static final int FILE_DEVICE_CHANGER = 0x00000030;
public static final int FILE_DEVICE_CONTROLLER = 0x00000004;
public static final int FILE_DEVICE_DATALINK = 0x00000005;
public static final int FILE_DEVICE_DFS = 0x00000006;
public static final int FILE_DEVICE_DFS_FILE_SYSTEM = 0x00000035;
public static final int FILE_DEVICE_DFS_VOLUME = 0x00000036;
public static final int FILE_DEVICE_DISK = 0x00000007;
public static final int FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008;
public static final int FILE_DEVICE_DVD = 0x00000033;
public static final int FILE_DEVICE_FILE_SYSTEM = 0x00000009;
public static final int FILE_DEVICE_FIPS = 0x0000003a;
public static final int FILE_DEVICE_FULLSCREEN_VIDEO = 0x00000034;
public static final int FILE_DEVICE_INPORT_PORT = 0x0000000a;
public static final int FILE_DEVICE_KEYBOARD = 0x0000000b;
public static final int FILE_DEVICE_KS = 0x0000002f;
public static final int FILE_DEVICE_KSEC = 0x00000039;
public static final int FILE_DEVICE_MAILSLOT = 0x0000000c;
public static final int FILE_DEVICE_MASS_STORAGE = 0x0000002d;
public static final int FILE_DEVICE_MIDI_IN = 0x0000000d;
public static final int FILE_DEVICE_MIDI_OUT = 0x0000000e;
public static final int FILE_DEVICE_MODEM = 0x0000002b;
public static final int FILE_DEVICE_MOUSE = 0x0000000f;
public static final int FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010;
public static final int FILE_DEVICE_NAMED_PIPE = 0x00000011;
public static final int FILE_DEVICE_NETWORK = 0x00000012;
public static final int FILE_DEVICE_NETWORK_BROWSER = 0x00000013;
public static final int FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014;
public static final int FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028;
public static final int FILE_DEVICE_NULL = 0x00000015;
public static final int FILE_DEVICE_PARALLEL_PORT = 0x00000016;
public static final int FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017;
public static final int FILE_DEVICE_PRINTER = 0x00000018;
public static final int FILE_DEVICE_SCANNER = 0x00000019;
public static final int FILE_DEVICE_SCREEN = 0x0000001c;
public static final int FILE_DEVICE_SERENUM = 0x00000037;
public static final int FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001a;
public static final int FILE_DEVICE_SERIAL_PORT = 0x0000001b;
public static final int FILE_DEVICE_SMARTCARD = 0x00000031;
public static final int FILE_DEVICE_SMB = 0x0000002e;
public static final int FILE_DEVICE_SOUND = 0x0000001d;
public static final int FILE_DEVICE_STREAMS = 0x0000001e;
public static final int FILE_DEVICE_TAPE = 0x0000001f;
public static final int FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020;
public static final int FILE_DEVICE_TERMSRV = 0x00000038;
public static final int FILE_DEVICE_TRANSPORT = 0x00000021;
public static final int FILE_DEVICE_UNKNOWN = 0x00000022;
public static final int FILE_DEVICE_VDM = 0x0000002c;
public static final int FILE_DEVICE_VIDEO = 0x00000023;
public static final int FILE_DEVICE_VIRTUAL_DISK = 0x00000024;
public static final int FILE_DEVICE_WAVE_IN = 0x00000025;
public static final int FILE_DEVICE_WAVE_OUT = 0x00000026;
}
10 changes: 10 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/SetupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public interface SetupApi extends StdCallLibrary {
*/
int SPDRP_REMOVAL_POLICY = 0x0000001F;

/**
* Eject supported.
*/
int CM_DEVCAP_EJECTSUPPORTED = 0x00000002;

/**
* Removable.
*/
Expand Down Expand Up @@ -121,6 +126,11 @@ public interface SetupApi extends StdCallLibrary {
*/
int SPDRP_DEVICEDESC = 0x00000000;

/**
* The function retrieves a REG_SZ string that contains the friendly name of a device.
*/
int SPDRP_FRIENDLYNAME = 0xc;

/**
* The SetupDiGetClassDevs function returns a handle to a device information set that contains requested device
* information elements for a local computer.
Expand Down
15 changes: 15 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/WinBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ public interface WinBase extends WinDef, BaseTSD {
int WAIT_ABANDONED = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );
int WAIT_ABANDONED_0 = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );

/**
* The standard input device. Initially, this is the console input buffer, CONIN$.
*/
DWORD STD_INPUT_HANDLE = new DWORD(-10);

/**
* The standard output device. Initially, this is the active console screen buffer, CONOUT$.
*/
DWORD STD_OUTPUT_HANDLE = new DWORD(-11);

/**
* The standard error device. Initially, this is the active console screen buffer, CONOUT$.
*/
DWORD STD_ERROR_HANDLE = new DWORD(-12);

/**
* Maximum computer name length.
* The value is 15 on Mac, 31 on everything else.
Expand Down
172 changes: 172 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/win32/WinNT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,108 @@ public interface LOGICAL_PROCESSOR_RELATIONSHIP {
int RelationAll = 0xFFFF;
}

/**
* Contains information about the relationships of logical processors and related hardware. The
* GetLogicalProcessorInformationEx function uses this structure.
*/
class SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX extends Structure {
/**
* The type of relationship between the logical processors.
*/
public WinDef.DWORD relationship;

/**
* The size of the structure.
*/
public WinDef.DWORD size;

/**
* A PROCESSOR_RELATIONSHIP structure that describes processor affinity. This structure contains valid data only if
* the Relationship member is RelationProcessorCore or RelationProcessorPackage.
*
* This is actually a union with the NUMA and other data types.
*/
public PROCESSOR_RELATIONSHIP processor;

public SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX()
{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave this empty - better to add the call to super() - even though it is implicit, as this enables placing a debug breakpoint in the constructor.


public SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX(Pointer pointer, int offset) {
useMemory(pointer, offset);
read();
}

@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("relationship", "size", "processor");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-style - open braces on same line as the method name...


/**
* Represents information about affinity within a processor group. This structure is used with the
* GetLogicalProcessorInformationEx function.
*/
class PROCESSOR_RELATIONSHIP extends Structure {
/**
* <p>If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is RelationProcessorCore,
* this member is LTP_PC_SMT if the core has more than one logical processor, or 0 if the core has one logical
* processor.</p>
*
* <p>If the Relationship member of the SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX structure is
* RelationProcessorPackage, this member is always 0.</p>
*/
public byte flags;

/**
* This member is reserved.
*/
public byte[] reserved = new byte[21];

/**
* This member specifies the number of entries in the GroupMask array.
*/
public WinDef.WORD groupCount;

/**
* An array of GROUP_AFFINITY structures. The GroupCount member specifies the number of structures in the array.
* Each structure in the array specifies a group number and processor affinity within the group.
*/
public GROUP_AFFINITY[] groupMask = new GROUP_AFFINITY[1];

@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("flags", "reserved", "groupCount", "groupMask");
}
}

/**
* Represents a processor group-specific affinity, such as the affinity of a thread.
*/
public class GROUP_AFFINITY extends Structure {
/**
* A bitmap that specifies the affinity for zero or more processors within the specified group.
*/
public BaseTSD.ULONG_PTR mask;

/**
* The processor group number.
*/
public WinDef.WORD group;

/**
* This member is reserved.
*/
public WinDef.WORD[] reserved = new WinDef.WORD[3];

@Override
protected List<String> getFieldOrder()
{
return Arrays.asList("mask", "group", "reserved");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style - open braces on same line as the method name

}

byte CACHE_FULLY_ASSOCIATIVE = (byte)0xFF;

/**
Expand Down Expand Up @@ -2996,4 +3098,74 @@ protected List getFieldOrder() {
});
}
}

/**
* Contains information about a range of pages in the virtual address space of a process.
*/
class MEMORY_BASIC_INFORMATION64 extends Structure {
/**
* A pointer to the base address of the region of pages.
*/
public ULONGLONG baseAddress;

/**
* A pointer to the base address of a range of pages allocated by the VirtualAlloc function.
* The page pointed to by the BaseAddress member is contained within this allocation range.
*/
public ULONGLONG allocationBase;

/**
* The memory protection option when the region was initially allocated. This member can be
* one of the memory protection constants or 0 if the caller does not have access.
*/
public DWORD allocationProtect;

public DWORD __alignment1;

/**
* The size of the region beginning at the base address in which all pages have identical
* attributes, in bytes.
*/
public ULONGLONG regionSize;

/**
* The state of the pages in the region.
*/
public DWORD state;

/**
* The access protection of the pages in the region. This member is one of the values listed
* for the AllocationProtect member.
*/
public DWORD protect;

/**
* The type of pages in the region.
*/
public DWORD type;
public DWORD __alignment2;

public static class ByReference extends MEMORY_BASIC_INFORMATION64 implements Structure.ByReference {
public ByReference() {
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave this empty - add call to (implicit) super() as this enables setting a breakpoint in the constructor

public ByReference(Pointer memory) {
super(memory);
}
}

public MEMORY_BASIC_INFORMATION64() {
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave this empty - add call to (implicit) super() as this enables setting a breakpoint in the constructor.


public MEMORY_BASIC_INFORMATION64(Pointer memory) {
super(memory);
read();
}

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("baseAddress", "allocationBase", "allocationProtect", "__alignment1", "regionSize",
"state", "protect", "type", "__alignment2");
}
}
}
Loading