-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exception from COMBindingBaseObject swallows real reason + HRESULT
The exception thrown from COMBindingBaseObject when instatiation fails is misleading: COM object with CLSID {0002DF01-0000-0000-C000-000000000046} not registered properly! In the concrete case COM was not properly initialized, the same error now reports (in german locale): CoInitialize wurde nicht aufgerufen.(HRESULT: 800401f0) (puArgErr=) For english locale this should be along the lines of: CoInitialize was not called.(HRESULT: 800401f0) (puArgErr=) The message now points out the correct problem (as far as the windows error code translation works) and the HRESULT can be used for a locale independend report + search. Closes #646
- Loading branch information
1 parent
0296115
commit 2c4a471
Showing
3 changed files
with
74 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...b/platform/test/com/sun/jna/platform/win32/COM/ComExceptionWithoutInitializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.sun.jna.platform.win32.COM; | ||
|
||
import com.sun.jna.platform.win32.Guid; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public class ComExceptionWithoutInitializationTest { | ||
|
||
@Test | ||
public void testCorrectExceptionOnFailedInitialization() { | ||
String message = null; | ||
try { | ||
InternetExplorer ie = new InternetExplorer(); | ||
} catch (COMException ex) { | ||
message = ex.getMessage(); | ||
} | ||
|
||
// This invocation must raise an exception, as the COM thread is not | ||
// initialized, in the message it is expected, that the HRESULT is reported | ||
// and the HRESULT resulting from calling into COM with it being initialized | ||
// is 800401f0. The message is also expected to point the to correct | ||
// initialization via CoInitialize | ||
assertNotNull(message); | ||
assertTrue(message.contains("HRESULT")); | ||
assertTrue(message.contains("800401f0")); | ||
assertTrue(message.contains("CoInitialize")); | ||
} | ||
|
||
/** | ||
* InternetExplorer / IWebBrowser2 - see | ||
* http://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx | ||
*/ | ||
private static class InternetExplorer extends COMLateBindingObject { | ||
|
||
public InternetExplorer(IDispatch iDispatch) { | ||
super(iDispatch); | ||
} | ||
|
||
public InternetExplorer() { | ||
super(new Guid.CLSID("{0002DF01-0000-0000-C000-000000000046}"), true); | ||
} | ||
|
||
/** | ||
* IWebBrowser2::get_LocationURL<br> | ||
* Read-only COM property.<br> | ||
* | ||
* @return the URL of the resource that is currently displayed. | ||
*/ | ||
public String getURL() { | ||
return getStringProperty("LocationURL"); | ||
} | ||
} | ||
} |