diff --git a/CHANGES.md b/CHANGES.md index fae7c2d78b..9357f529da 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,7 @@ Bug Fixes * [#382](https://github.com/twall/jna/pull/382): Fixed memory allocation in `com.sun.jna.platform.win32.WTypes.LPWSTR` and `LPSTR` constructors - [@junak-michal](https://github.com/junak-michal). * Fix publish doc links - [@bhamail](https://github.com/bhamail). * [#388](https://github.com/twall/jna/issues/388): Ensure native library always opened with provided flags - [@zolyfarkas](https://github.com/zolyfarkas). +* [#403](https://github.com/twall/jna/pull/403): Make com.sun.jna.platform.win32.COM.COMUtils.SUCCEEDED and FAILED conform to MSDN specification for said macros - [@lwahonen](https://github.com/lwahonen). Release 4.1 =========== diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java index eddbbd48f8..9bdfcace8d 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java @@ -73,8 +73,7 @@ public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance, int dwClsContext) { // Initialize COM for this thread... HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_APARTMENTTHREADED); - if (hr.intValue() == 1) // Already initialized, no problem - hr = new HRESULT(0); + if (COMUtils.FAILED(hr)) { Ole32.INSTANCE.CoUninitialize(); throw new COMException("CoInitialize() failed!"); @@ -108,8 +107,6 @@ public COMBindingBaseObject(String progId, boolean useActiveInstance, int dwClsContext) throws COMException { // Initialize COM for this thread... HRESULT hr = Ole32.INSTANCE.CoInitializeEx(null, Ole32.COINIT_APARTMENTTHREADED); - if (hr.intValue() == 1) // Already initialized, no problem - hr = new HRESULT(0); if (COMUtils.FAILED(hr)) { this.release(); diff --git a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java index b362d0c9a8..d2e15e44a0 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/COM/COMUtils.java @@ -38,6 +38,8 @@ public abstract class COMUtils { /** The Constant CO_E_NOTINITIALIZED. */ public static final int S_OK = 0; + public static final int S_FALSE = 1; + public static final int E_UNEXPECTED=0x8000FFFF; /** * Succeeded. @@ -58,10 +60,7 @@ public static boolean SUCCEEDED(HRESULT hr) { * @return true, if successful */ public static boolean SUCCEEDED(int hr) { - if (hr == S_OK) - return true; - else - return false; + return hr >= 0; } /** @@ -83,7 +82,7 @@ public static boolean FAILED(HRESULT hr) { * @return true, if successful */ public static boolean FAILED(int hr) { - return (hr != S_OK); + return hr < 0; } /** diff --git a/contrib/platform/test/com/sun/jna/platform/win32/COM/COMUtilsTest.java b/contrib/platform/test/com/sun/jna/platform/win32/COM/COMUtilsTest.java new file mode 100644 index 0000000000..56aac85142 --- /dev/null +++ b/contrib/platform/test/com/sun/jna/platform/win32/COM/COMUtilsTest.java @@ -0,0 +1,18 @@ +package com.sun.jna.platform.win32.COM; + +import junit.framework.TestCase; + +public class COMUtilsTest extends TestCase { + + public void testSUCCEEDED() throws Exception { + assertTrue(COMUtils.SUCCEEDED(COMUtils.S_OK)); + assertTrue(COMUtils.SUCCEEDED(COMUtils.S_FALSE)); + assertFalse(COMUtils.SUCCEEDED(COMUtils.E_UNEXPECTED)); + } + + public void testFAILED() throws Exception { + assertFalse(COMUtils.FAILED(COMUtils.S_OK)); + assertFalse(COMUtils.FAILED(COMUtils.S_FALSE)); + assertTrue(COMUtils.FAILED(COMUtils.E_UNEXPECTED)); + } +} \ No newline at end of file