Can't access methods in COM interface

225 views
Skip to first unread message

Charlie Stedman

unread,
Oct 17, 2013, 12:34:40 PM10/17/13
to jna-...@googlegroups.com
I'm new to JNA but it seems like it should do exactly what I need but I'm having some trouble.

I'm trying to set overlay icons on my applications task bar icon using the Windows ITaskbarList3::SetOverlayIcon method.  The problem is when I try and call this from my JNA java code, I get told the method doesn't exist.  I think this is because the method I'm calling is defined inside an INTERFACE in the C header file so I can't refer to it directly.  I think this is a COM thing.  JNA claims support for that but I haven't been able to figure out how to get it working or any example code.  Can anyone help?

Here's the header file definition of the method I'm trying to call (from shobjidl.h):

#define INTERFACE ITaskbarList3
DECLARE_INTERFACE_(ITaskbarList3, ITaskbarList2)
{
STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
STDMETHOD(HrInit)(THIS) PURE;
STDMETHOD(AddTab)(THIS_ HWND) PURE;
STDMETHOD(DeleteTab)(THIS_ HWND) PURE;
STDMETHOD(ActivateTab)(THIS_ HWND) PURE;
STDMETHOD(SetActiveAlt)(THIS_ HWND) PURE;
STDMETHOD(MarkFullscreenWindow)(THIS_ HWND,BOOL) PURE;
STDMETHOD(SetProgressValue)(THIS_ ULONGLONG,ULONGLONG) PURE;
STDMETHOD(SetProgressState)(THIS_ HWND,TBPFLAG) PURE;
STDMETHOD(RegisterTab)(THIS_ HWND,HWND) PURE;
STDMETHOD(UnregisterTab)(THIS_ HWND) PURE;
STDMETHOD(SetTabOrder)(THIS_ HWND,HWND) PURE;
STDMETHOD(SetTabActive)(THIS_ HWND,HWND,DWORD) PURE;
STDMETHOD(ThumbBarAddButtons)(THIS_ HWND,UINT,LPTHUMBBUTTON) PURE;
STDMETHOD(ThumbBarUpdateButtons)(THIS_ HWND,UINT,LPTHUMBBUTTON) PURE;
STDMETHOD(ThumbBarSetImageList)(THIS_ HWND,HIMAGELIST) PURE;
STDMETHOD(SetOverlayIcon)(THIS_ HWND,HICON,LPCWSTR) PURE;
STDMETHOD(SetThumbnailTooltip)(THIS_ HWND,LPCWSTR) PURE;
STDMETHOD(SetThumbnailClip)(THIS_ HWND,RECT*) PURE;
};
#undef INTERFACE
typedef ITaskbarList3 *LPTASKBARLIST3;

Tobias Wolf

unread,
Oct 17, 2013, 1:13:16 PM10/17/13
to jna-...@googlegroups.com

Please provide the way how you create the code to access the com object.

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Charlie Stedman

unread,
Oct 18, 2013, 5:21:08 AM10/18/13
to jna-...@googlegroups.com
Here's the code.  I haven't done anything special to try and access the method as a COM object as I don't know how to do that.

public interface OverlayApi
    extends Library
{
    OverlayApi INSTANCE = (OverlayApi) Native.loadLibrary("ExplorerFrame", OverlayApi.class);

    public HRESULT SetOverlayIcon(HWND hwnd, HICON hIcon, Pointer pszDescription);
}

String description = "Test description";
Pointer descPtr = new Memory(description.length() + 1);
descPtr.setString(0, description);
OverlayApi.INSTANCE.SetOverlayIcon(null, null, descPtr);

This results in the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Error looking up function 'SetOverlayIcon': The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:179)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:344)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:324)
at com.sun.jna.Library$Handler.invoke(Library.java:203)
at com.sun.proxy.$Proxy0.SetOverlayIcon(Unknown Source)
at net.testOpeningFile.TestOpeningFile.changeOverlay(TestOpeningFile.java:49)

Tobias Wolf

unread,
Oct 18, 2013, 12:23:29 PM10/18/13
to jna-...@googlegroups.com
Hi,
 
the way you`ve tried is to load a standard windows library. For COM libs you should generate a java wrapper from the type library with the TlbImp Tool which is part of the JNA project. Start the java main method and read the console output for more details. 
 
Gesendet: Freitag, 18. Oktober 2013 um 11:21 Uhr
Von: "Charlie Stedman" <stedman...@gmail.com>
An: jna-...@googlegroups.com
Betreff: Re: Can't access methods in COM interface

Charlie Stedman

unread,
Oct 21, 2013, 5:03:38 AM10/21/13
to jna-...@googlegroups.com
Thanks for the tip.  That makes much more sense now.  But unfortunately it doesn't work for the library I'm trying to use.  If I run tlbimp on shell32.dll (as in the example) it completes OK but if I run it on explorerframe.dll I get the following error:

Exception in thread "main" com.sun.jna.platform.win32.COM.COMException: Error loading type library/DLL.
at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:115)
at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:98)
at com.sun.jna.platform.win32.COM.TypeLibUtil.<init>(TypeLibUtil.java:96)
at com.sun.jna.platform.win32.COM.tlb.TlbImp.<init>(TlbImp.java:76)
at com.sun.jna.platform.win32.COM.tlb.TlbImp.main(TlbImp.java:54)

This works: -tlb.file c:\windows\System32\Shell32.dll
This doesn't: -tlb.file c:\windows\System32\ExplorerFrame.dll
Neither does this: -tlb.file c:\windows\SysWOW64\ExplorerFrame.dll

This suggests that explorerframe.dll isn't a typelib.  But I don't understand why not.

Also, when I run the shell32 one, although it completes, it doesn't produce any methods matching ITaskbarList2::MarkFullscreenWindow, which is the most similar to the method I want ITaskbarList3::SetOverlayIcon

Any ideas?

Thanks!

Tobias Wolf

unread,
Oct 21, 2013, 7:02:14 AM10/21/13
to jna-...@googlegroups.com
You should make clear that the dll your are refering to includes the tlb definition/library. Usally you find that information at the microsoft page.
 
Gesendet: Montag, 21. Oktober 2013 um 11:03 Uhr

Von: "Charlie Stedman" <stedman...@gmail.com>
An: jna-...@googlegroups.com
Betreff: Re: Re: Can't access methods in COM interface
Reply all
Reply to author
Forward
0 new messages