我的目标是生成桥接代码,允许在Java中调用COM接口。我确实成功地使用了jna,只要我获得了接口的句柄,并且能够成功地使用接口的大部分功能。
我有一个关于几个类似于以下模式的接口的问题(我认为代码片段是自包含的):
[
odl,
uuid(4D27AA78-B622-42E7-A237-3DA76B14A23D),
helpstring("IVariables Interface"),
dual,
oleautomation
]
interface IVariables : IDispatch {
[id(0x00000001), propget, helpstring("property Application")]
HRESULT Application([out, retval] IDispatch** pVal);
[id(0x00000002), propget, helpstring("property Parent")]
HRESULT Parent([out, retval] IDispatch** pVal);
[id(0x00000003), propget, helpstring("property Count")]
HRESULT Count([out, retval] long* pnCount);
[id(00000000), propget, helpstring("property Item")]
HRESULT Item(
[in] VARIANT index,
[out, retval] IVariable** pVal);
[id(0xfffffffc), propget, helpstring("property _NewEnum")]
HRESULT _NewEnum([out, retval] IUnknown** ppEnum);
[id(0x00000004), helpstring("method Add")]
HRESULT Add(
[in] BSTR Name,
[in, optional] VARIANT Value,
[out, retval] IVariable** pVal);
[id(0x00000005), helpstring("method Remove")]
HRESULT Remove([in] VARIANT index);
};
如果这个接口被导入到visual studio并在c项目中使用,那么c会检测到上面的实现了这个接口
IEnumerator
并允许在元素上迭代。此外,c甚至知道迭代类型,是一个“ivvariable”。
问题1:C或其COM接口导入程序如何得出结论,上面的“ivvariable”实现了“IEnumerator”,并且枚举的元素属于“ivvariable”类型?
很明显这条线
[id(0xfffffffc), propget, helpstring("property _NewEnum")]
一定要玩这个把戏。但是,虽然我在其他idl中找到了相同的构造,但在google中找不到任何解释。可能与此相关的是,我没有从idl获得任何关于属性类型的信息,请参见
[id(0x00000002), propget, helpstring("property Parent")]
在上面的IDL中。既没有类型“parent”,也没有类型“iparent”。因此:
问题2:是否可以从其idl派生com属性的类型,如果可以,如何派生?
最后,当将上述类型导入到c中时,实际上不使用上述idl。相反,导入程序希望启用OLE的应用程序的可执行文件读取其类型库(类似于Microsoft OleView.exe工具)。这就引出了我的最后一个问题:
问题3:是否有一个API可以用来查询可执行文件的OLE接口,这是否提供附加元数据?
谢谢你的洞察力。