Skip to content

Commit 5283b2b

Browse files
authored
Merge branch 'master' into structure-fieldorder
2 parents f16aba0 + 5936a34 commit 5283b2b

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,9 @@ public void write() {
28022802

28032803
@Override
28042804
public void read() {
2805+
if(SidStart == null) {
2806+
SidStart = new byte[4];
2807+
}
28052808
super.read();
28062809
int offsetOfSID = super.fieldOffset("SidStart");
28072810
int sizeOfSID = super.AceSize - super.fieldOffset("SidStart");

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.sun.jna.platform.win32.WinUser.MONITORENUMPROC;
5050
import com.sun.jna.platform.win32.WinUser.MONITORINFO;
5151
import com.sun.jna.platform.win32.WinUser.MONITORINFOEX;
52+
import org.junit.Before;
5253

5354
/**
5455
* @author dblock[at]dblock[dot]org
@@ -59,6 +60,11 @@ public static void main(String[] args) {
5960
JUnitCore.runClasses(User32Test.class);
6061
}
6162

63+
@Before
64+
public void setUp() {
65+
Native.setLastError(0);
66+
}
67+
6268
/**
6369
* Iterates over all currently available Desktop windows and searches for
6470
* the window with the associated process whose full PE file path ends with
@@ -339,7 +345,6 @@ public void testIsWindowEnabled() {
339345
public void testIsWindow() {
340346
boolean iwResult = User32.INSTANCE.IsWindow(null);
341347
assertFalse("IsWindow result should be false", iwResult);
342-
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
343348
}
344349

345350
@Test
@@ -356,7 +361,6 @@ public void testGetAncestor() {
356361

357362
HWND result = User32.INSTANCE.GetAncestor(desktopWindow, WinUser.GA_PARENT);
358363
assertNull("GetAncestor result should be null", result);
359-
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
360364
}
361365

362366
@Test
@@ -414,10 +418,8 @@ public void testGetClassLong() {
414418

415419
@Test
416420
public void testGetActiveWindow() {
417-
418421
HWND result = User32.INSTANCE.GetActiveWindow();
419-
assertNull("GetActiveWindow result should be null", result);
420-
assertEquals("GetLastError should be ERROR_SUCCESS.", WinError.ERROR_SUCCESS, Native.getLastError());
422+
assertNull("GetActiveWindow result should be null (there is no active window)", result);
421423
}
422424

423425
@Test

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

+18-19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package com.sun.jna.platform.win32;
2424

25+
import com.sun.jna.Native;
2526
import com.sun.jna.Pointer;
2627
import com.sun.jna.platform.win32.Winsvc.HandlerEx;
2728
import com.sun.jna.platform.win32.Winsvc.SC_HANDLE;
@@ -33,7 +34,7 @@
3334
import java.io.File;
3435
import java.net.URISyntaxException;
3536
import java.net.URL;
36-
import java.net.URLClassLoader;
37+
import java.security.ProtectionDomain;
3738
import java.util.HashSet;
3839
import java.util.Set;
3940
import java.util.logging.Level;
@@ -100,29 +101,27 @@ public static boolean install() {
100101
// a) an URLClassLoader
101102
// b) holds all relevant dependencies
102103
String invocation;
103-
ClassLoader cl = W32ServiceTest.class.getClassLoader();
104-
if (cl instanceof URLClassLoader) {
105-
StringBuilder sb = new StringBuilder();
106-
for (URL u : ((URLClassLoader) cl).getURLs()) {
107-
if ("file".equals(u.getProtocol())) {
108-
try {
109-
File f = new File(u.toURI());
110-
if (SUFFIXES.contains(f.getName())) {
111-
if (sb.length() != 0) {
112-
sb.append(";");
113-
}
114-
sb.append(f.getAbsolutePath());
104+
StringBuilder sb = new StringBuilder();
105+
for(Class c : new Class[]{W32ServiceTest.class,Native.class,W32Service.class}) {
106+
ProtectionDomain pd = c.getProtectionDomain();
107+
URL u = pd.getCodeSource().getLocation();
108+
109+
if ("file".equals(u.getProtocol())) {
110+
try {
111+
File f = new File(u.toURI());
112+
if (SUFFIXES.contains(f.getName())) {
113+
if (sb.length() != 0) {
114+
sb.append(";");
115115
}
116-
} catch (URISyntaxException ex) {
117-
Logger.getLogger(W32ServiceTest.class.getName()).log(Level.SEVERE, null, ex);
116+
sb.append(f.getAbsolutePath());
118117
}
118+
} catch (URISyntaxException ex) {
119+
Logger.getLogger(W32ServiceTest.class.getName()).log(Level.SEVERE, null, ex);
119120
}
120121
}
121-
invocation = String.format("java.exe -cp %s com.sun.jna.platform.win32.Win32ServiceDemo", sb.toString());
122-
System.out.println("Invocation: " + invocation);
123-
} else {
124-
throw new IllegalStateException("Classloader loading Win32ServiceDemo must be an URLClassLoader");
125122
}
123+
invocation = String.format("java.exe -cp %s com.sun.jna.platform.win32.Win32ServiceDemo", sb.toString());
124+
System.out.println("Invocation: " + invocation);
126125

127126
SERVICE_DESCRIPTION desc = new SERVICE_DESCRIPTION();
128127
desc.lpDescription = description;

src/com/sun/jna/win32/DLLCallback.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
*/
3434
public interface DLLCallback extends Callback {
3535
/** Total number of DLL callbacks available for allocation. */
36+
@java.lang.annotation.Native
3637
int DLL_FPTRS = 16;
3738
}

0 commit comments

Comments
 (0)