Skip to content

Commit

Permalink
Merge pull request #403 from lwahonen/upstream
Browse files Browse the repository at this point in the history
Fix SUCCEEDED and FAILED instead of trying to fix the bug where it's vis...
  • Loading branch information
dblock committed Mar 16, 2015
2 parents 2fe2386 + fe79ff8 commit de3a9ea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit de3a9ea

Please sign in to comment.