Skip to content

Commit 8dc9db6

Browse files
author
Eran Leshem
committed
Addressed comments
1 parent 4f271ca commit 8dc9db6

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

contrib/platform/src/com/sun/jna/platform/win32/WinUser.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,25 +2097,59 @@ public HPOWERNOTIFY(Pointer pointer) {
20972097
}
20982098
}
20992099

2100+
/**
2101+
* Registers the application to receive power setting notifications for the specific power setting event.
2102+
* @param hRecipient Handle indicating where the power setting notifications are to be sent.
2103+
* For interactive applications, the Flags parameter should be DEVICE_NOTIFY_WINDOW_HANDLE,
2104+
* and the hRecipient parameter should be a window handle.
2105+
* For services, the Flags parameter should be DEVICE_NOTIFY_SERVICE_HANDLE, and the hRecipient
2106+
* parameter should be a SERVICE_STATUS_HANDLE as returned from RegisterServiceCtrlHandlerEx.
2107+
* @param PowerSettingGuid The GUID of the power setting for which notifications are to be sent.
2108+
* @param Flags
2109+
* <li>DEVICE_NOTIFY_WINDOW_HANDLE - Notifications are sent using WM_POWERBROADCAST messages
2110+
* with a wParam parameter of PBT_POWERSETTINGCHANGE.
2111+
* <li>DEVICE_NOTIFY_SERVICE_HANDLE - Notifications are sent to the HandlerEx callback function with a dwControl
2112+
* parameter of SERVICE_CONTROL_POWEREVENT and a dwEventType of PBT_POWERSETTINGCHANGE.
2113+
* @return a notification handle for unregistering for power notifications. If the function fails, the return
2114+
* value is NULL. To get extended error information, call GetLastError.
2115+
*/
21002116
HPOWERNOTIFY RegisterPowerSettingNotification(
21012117
/*[in]*/ HANDLE hRecipient,
21022118
/*[in]*/ Guid.GUID PowerSettingGuid,
2103-
/*[in]*/ DWORD Flags);
2119+
/*[in]*/ int Flags);
21042120

2121+
/**
2122+
* Unregisters the power setting notification.
2123+
* @param Handle The handle returned from the RegisterPowerSettingNotification function.
2124+
* @return If the function succeeds, the return value is nonzero.
2125+
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
2126+
*/
21052127
BOOL UnregisterPowerSettingNotification(
21062128
/*[in]*/ HPOWERNOTIFY Handle
21072129
);
21082130

21092131
int WM_POWERBROADCAST = 0x0218;
2132+
2133+
int PBT_APMQUERYSUSPEND = 0x0000;
2134+
int PBT_APMQUERYSTANDBY = 0x0001;
2135+
int PBT_APMQUERYSUSPENDFAILED = 0x0002;
2136+
int PBT_APMQUERYSTANDBYFAILED = 0x0003;
21102137
int PBT_APMSUSPEND = 0x0004;
2138+
int PBT_APMSTANDBY = 0x0005;
2139+
int PBT_APMRESUMECRITICAL = 0x0006;
2140+
int PBT_APMRESUMESUSPEND = 0x0007;
2141+
int PBT_APMRESUMESTANDBY = 0x0008;
2142+
int PBT_APMBATTERYLOW = 0x0009;
2143+
int PBT_APMPOWERSTATUSCHANGE = 0x000A;
2144+
int PBT_APMOEMEVENT = 0x000B;
21112145
int PBT_APMRESUMEAUTOMATIC = 0x0012;
21122146
int PBT_POWERSETTINGCHANGE = 0x8013;
21132147

21142148
@FieldOrder({"PowerSetting", "DataLength", "Data"})
21152149
class POWERBROADCAST_SETTING extends Structure {
21162150
public Guid.GUID PowerSetting;
2117-
public DWORD DataLength;
2118-
public UCHAR Data[] = new UCHAR[1];
2151+
public int DataLength;
2152+
public byte Data[] = new byte[1];
21192153

21202154
public POWERBROADCAST_SETTING(Pointer p) {
21212155
super(p);
@@ -2124,9 +2158,8 @@ public POWERBROADCAST_SETTING(Pointer p) {
21242158

21252159
@Override
21262160
public final void read() {
2127-
int size = (int) getPointer().getLong(fieldOffset("DataLength"));
2128-
Data = new UCHAR[size];
2129-
super.read();
2161+
Data = new byte[getPointer().getInt(fieldOffset("DataLength"))];
2162+
super.read();
21302163
}
21312164
}
21322165
}

contrib/platform/test/com/sun/jna/platform/win32/User32Test.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,4 +596,12 @@ public void testToUnicodeEx() {
596596
// which is in an undefined state at test execution and may change arbitrarily
597597
// during the test.
598598
}
599+
600+
@Test
601+
public void testRegisterPowerSettingNotification() {
602+
WinUser.HPOWERNOTIFY hpowernotify = INSTANCE.RegisterPowerSettingNotification(
603+
new HWND(), WinNT.GUID_CONSOLE_DISPLAY_STATE, User32.DEVICE_NOTIFY_WINDOW_HANDLE);
604+
assertNotNull(hpowernotify);
605+
assertNotEquals(0, INSTANCE.UnregisterPowerSettingNotification(hpowernotify));
606+
}
599607
}

0 commit comments

Comments
 (0)