Skip to content

Commit

Permalink
Merge pull request #683 from matthiasblaesing/dword_extract_high_low_…
Browse files Browse the repository at this point in the history
…word

Use correct bit masks when extracting low/high word from DWORD
  • Loading branch information
matthiasblaesing committed Jul 26, 2016
2 parents 567f916 + a197201 commit c3cb85a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Bug Fixes
* [#646](https://github.com/java-native-access/jna/issues/646): `platform.win32.COM.COMBindingBaseObject` swallows reason if instantiation fails - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#674](https://github.com/java-native-access/jna/pull/674): Update references to Apache License as requested by issue #673 [@bhamail](https://github.com/bhamail)
* [#636](https://github.com/java-native-access/jna/issues/636): Staticly link visual c++ runtime when building with MSVC - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#624](https://github.com/java-native-access/jna/issues/624): WinDef.DWORD getLow() & getHigh() using incorrect bit mask - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 4.2.1
=============
Expand Down
4 changes: 2 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/win32/WinDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public DWORD(long value) {
* @return Low WORD.
*/
public WORD getLow() {
return new WORD(longValue() & 0xFF);
return new WORD(longValue() & 0xFFFF);
}

/**
Expand All @@ -148,7 +148,7 @@ public WORD getLow() {
* @return High WORD.
*/
public WORD getHigh() {
return new WORD((longValue() >> 16) & 0xFF);
return new WORD((longValue() >> 16) & 0xFFFF);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void testOpenProcess() {

public void testQueryFullProcessImageName() {
int pid = Kernel32.INSTANCE.GetCurrentProcessId();
HANDLE h = Kernel32.INSTANCE.OpenProcess(0, false, pid);
HANDLE h = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_QUERY_INFORMATION, false, pid);
assertNotNull("Failed (" + Kernel32.INSTANCE.GetLastError() + ") to get process ID=" + pid + " handle", h);

try {
Expand Down
44 changes: 44 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/WinDefTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

package com.sun.jna.platform.win32;

import com.sun.jna.platform.win32.WinDef.DWORD;
import com.sun.jna.platform.win32.WinDef.WORD;
import org.junit.Test;
import static org.junit.Assert.*;

public class WinDefTest {

@Test
public void testWordExtractionFromDword() {
DWORD dword = new DWORD(0x12345678);

assertEquals(new WORD(0x5678), dword.getLow());
assertEquals(new WORD(0x1234), dword.getHigh());

DWORD dword2 = new DWORD(0xFFFFFFFF);

assertEquals(new WORD(0xFFFF), dword2.getLow());
assertEquals(new WORD(0xFFFF), dword2.getHigh());

DWORD dword3 = new DWORD(0x00000001);

assertEquals(new WORD(0x0001), dword3.getLow());
assertEquals(new WORD(0x0000), dword3.getHigh());

DWORD dword4 = new DWORD(0x00010000);

assertEquals(new WORD(0x0000), dword4.getLow());
assertEquals(new WORD(0x0001), dword4.getHigh());

DWORD dword5 = new DWORD(0x0000FFFF);

assertEquals(new WORD(0xFFFF), dword5.getLow());
assertEquals(new WORD(0x0000), dword5.getHigh());

DWORD dword6 = new DWORD(0xFFFF0000);

assertEquals(new WORD(0x0000), dword6.getLow());
assertEquals(new WORD(0xFFFF), dword6.getHigh());
}

}

0 comments on commit c3cb85a

Please sign in to comment.