{"record":{"id":"be841a323a9b3a16","repo":"java-native-access/jna","slug":"queryinterface-formatmessagefromhr","errorCode":null,"errorMessage":"queryInterface: <formatMessageFromHR>","messagePattern":"queryInterface: <formatMessageFromHR>","errorType":"exception","errorClass":"com.sun.jna.platform.win32.COM.COMException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java","lineNumber":502,"sourceCode":"                throw new COMException(\n                        \"queryInterface: Interface must define a value for iid via the ComInterface annotation\");\n            }\n            final IID iid = this.getIID(comInterfaceAnnotation);\n            final PointerByReference ppvObject = new PointerByReference();\n\n            HRESULT hr = ProxyObject.this.getRawDispatch().QueryInterface(new REFIID(iid), ppvObject);\n\n            if (WinNT.S_OK.equals(hr)) {\n                Dispatch dispatch = new Dispatch(ppvObject.getValue());\n                T t = this.factory.createProxy(comInterface, dispatch);\n                // QueryInterface returns a COM object pointer with a +1\n                // reference, we must drop one,\n                // Note: createProxy adds one;\n                int n = dispatch.Release();\n                return t;\n            } else {\n                String formatMessageFromHR = Kernel32Util.formatMessage(hr);\n                throw new COMException(\"queryInterface: \" + formatMessageFromHR, hr);\n            }\n        } catch (RuntimeException e) {\n            // Do not rewrap COMException\n            if (e instanceof COMException) {\n                throw e;\n            } else {\n                throw new COMException(\"Error occured when trying to query for interface \" + comInterface.getName(), e);\n            }\n        }\n    }\n\n    private IID getIID(ComInterface annotation) {\n        String iidStr = annotation.iid();\n        if (null != iidStr && !iidStr.isEmpty()) {\n            return new IID(iidStr);\n        } else {\n            throw new COMException(\"ComInterface must define a value for iid\");\n        }","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java#L484-L520","documentation":"This COMException is raised by ProxyObject.queryInterface() when the underlying IDispatch.QueryInterface call returns a failed HRESULT. The Windows-format message for that HRESULT (via Kernel32Util.formatMessage) is appended, e.g. E_NOINTERFACE. It means the COM object does not support (or could not provide) the requested interface.","triggerScenarios":"The COM object does not implement the requested interface (E_NOINTERFACE); the object was released or marshaled incorrectly; the IID is valid but unsupported by the running server version.","commonSituations":"Querying an optional interface the server version doesn't support; wrong GUID casing/GUID from a different type library; calling QI after the object left its apartment.","solutions":["Check getHresult() — 0x80004002 (E_NOINTERFACE) means the object simply doesn't support it; guard that case","Verify the @ComInterface iid against the server's type library","Ensure COM apartment rules are respected (CoInitialize, same-thread or marshaled access)","Catch COMException and fall back to another interface or a different API surface"],"exampleFix":"// before\nFoo foo = proxy.queryInterface(Foo.class); // may E_NOINTERFACE\n// after\ntry {\n    Foo foo = proxy.queryInterface(Foo.class);\n} catch (COMException e) {\n    if (e.getHresult().intValue() == 0x80004002) { /* interface unsupported */ }\n}","handlingStrategy":"try-catch","validationCode":"String iid = comInterface.getAnnotation(ComInterface.class).iid(); if (iid == null || iid.isEmpty()) throw new IllegalArgumentException(\"missing iid\");","typeGuard":"boolean supported = false; try { proxy.queryInterface(Foo.class); supported = true; } catch (COMException e) { supported = e.getHresult().intValue() != 0x80004002; }","tryCatchPattern":"try { Foo f = proxy.queryInterface(Foo.class); } catch (COMException e) { if (e.getHresult() != null && e.getHresult().intValue() == 0x80004002) { /* E_NOINTERFACE: handle optional absence */ } else { throw e; } }","preventionTips":["Treat E_NOINTERFACE as an expected outcome for optional interfaces","Check server version supports the interface before QI","Keep proxies on their owning thread"],"tags":["com","hresult","queryinterface","windows"],"backgroundTag":"api-error-response","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}