Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SUCCEEDED and FAILED instead of trying to fix the bug where it's vis... #403

Merged
merged 1 commit into from
Mar 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}