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

Improve binding of TypeLib bindings #593

Merged
merged 1 commit into from
Feb 10, 2016
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 @@ -44,6 +44,7 @@ Bug Fixes
* [#566](https://github.com/java-native-access/jna/pull/566): Fix return type of Native#loadLibrary to match unconstrained generic [@lgoldstein](https://github.com/lgoldstein)
* [#584](https://github.com/java-native-access/jna/pull/584): Promote float varargs to double - [@marco2357](https://github.com/marco2357).
* [#588](https://github.com/java-native-access/jna/pull/588): Fix varargs calls on arm - [@twall](https://github.com/twall).
* [#593](https://github.com/java-native-access/jna/pull/593): Improve binding of TypeLib bindings - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 4.2.1
=============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package com.sun.jna.platform.win32.COM;

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Guid.GUID;
import com.sun.jna.platform.win32.OaIdl.MEMBERID;
import com.sun.jna.platform.win32.OaIdl.TLIBATTR;
Expand Down Expand Up @@ -69,9 +70,9 @@ public HRESULT IsName(

public HRESULT FindName(
/* [annotation][out][in] */
BSTRByReference szNameBuf,
LPOLESTR szNameBuf,
/* [in] */ULONG lHashVal,
/* [length_is][size_is][out] */PointerByReference ppTInfo,
/* [length_is][size_is][out] */Pointer[] ppTInfo,
/* [length_is][size_is][out] */MEMBERID[] rgMemId,
/* [out][in] */USHORTByReference pcFound);

Expand Down
12 changes: 5 additions & 7 deletions contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ public HRESULT GetDocumentation(
* @return the hresult
*/
public HRESULT IsName(
/* [annotation][out][in] */
LPOLESTR szNameBuf,
/* [annotation][out][in] */ LPOLESTR szNameBuf,
/* [in] */ULONG lHashVal,
/* [out] */BOOLByReference pfName) {

Expand All @@ -214,10 +213,9 @@ public HRESULT IsName(
* @return the hresult
*/
public HRESULT FindName(
/* [annotation][out][in] */
BSTRByReference szNameBuf,
/* [annotation][out][in] */ LPOLESTR szNameBuf,
/* [in] */ULONG lHashVal,
/* [length_is][size_is][out] */PointerByReference ppTInfo,
/* [length_is][size_is][out] */Pointer[] ppTInfo,
/* [length_is][size_is][out] */MEMBERID[] rgMemId,
/* [out][in] */USHORTByReference pcFound) {

Expand All @@ -233,7 +231,7 @@ public HRESULT FindName(
* the t lib attr
*/
public void ReleaseTLibAttr(/* [in] */TLIBATTR pTLibAttr) {
this._invokeNativeObject(12, new Object[] { this.getPointer() },
HRESULT.class);
this._invokeNativeObject(12, new Object[] { this.getPointer(),
pTLibAttr.getPointer() }, HRESULT.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package com.sun.jna.platform.win32.COM;

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.WString;
import com.sun.jna.platform.win32.Guid.CLSID;
Expand All @@ -21,6 +22,7 @@
import com.sun.jna.platform.win32.OaIdl.TYPEKIND;
import com.sun.jna.platform.win32.Ole32;
import com.sun.jna.platform.win32.OleAuto;
import com.sun.jna.platform.win32.WTypes;
import com.sun.jna.platform.win32.WTypes.BSTRByReference;
import com.sun.jna.platform.win32.WTypes.LPOLESTR;
import com.sun.jna.platform.win32.WinDef.BOOLByReference;
Expand Down Expand Up @@ -364,32 +366,29 @@ public boolean isName() {
* @param name
* the name
* @param hashVal
* the hash val
* @param found
* the found
* the hash val or 0 if unknown
* @param maxResult
* maximum number of items to search
* @return the find name
*/
public FindName FindName(String name, int hashVal, short found) {
/* [annotation][out][in] */
BSTRByReference szNameBuf = new BSTRByReference(
OleAuto.INSTANCE.SysAllocString(name));
/* [in] */ULONG lHashVal = new ULONG(hashVal);
/* [out][in] */USHORTByReference pcFound = new USHORTByReference(found);

HRESULT hr = this.typelib.FindName(szNameBuf, lHashVal, null, null,
pcFound);
COMUtils.checkRC(hr);
public FindName FindName(String name, int hashVal, short maxResult) {
Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((name.length() + 1L) * Native.WCHAR_SIZE);
WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p);
olestr.setValue(name);

found = pcFound.getValue().shortValue();
/* [length_is][size_is][out] */PointerByReference ppTInfo = new PointerByReference();
/* [length_is][size_is][out] */MEMBERID[] rgMemId = new MEMBERID[found];
hr = this.typelib.FindName(szNameBuf, lHashVal, ppTInfo, rgMemId,
ULONG lHashVal = new ULONG(hashVal);
USHORTByReference pcFound = new USHORTByReference(maxResult);

Pointer[] ppTInfo = new Pointer[maxResult];
MEMBERID[] rgMemId = new MEMBERID[maxResult];
HRESULT hr = this.typelib.FindName(olestr, lHashVal, ppTInfo, rgMemId,
pcFound);
COMUtils.checkRC(hr);

FindName findName = new FindName(szNameBuf.getString(), ppTInfo,
rgMemId, found);
OLEAUTO.SysFreeString(szNameBuf.getValue());
FindName findName = new FindName(olestr.getValue(), ppTInfo,
rgMemId, pcFound.getValue().shortValue());

Ole32.INSTANCE.CoTaskMemFree(p);

return findName;
}
Expand All @@ -405,7 +404,7 @@ public static class FindName {
private String nameBuf;

/** The p t info. */
private PointerByReference pTInfo;
private Pointer[] pTInfo;

/** The rg mem id. */
private MEMBERID[] rgMemId;
Expand All @@ -423,12 +422,14 @@ public static class FindName {
* the rg mem id
* @param pcFound
*/
public FindName(String nameBuf, PointerByReference pTInfo, MEMBERID[] rgMemId,
FindName(String nameBuf, Pointer[] pTInfo, MEMBERID[] rgMemId,
short pcFound) {
this.nameBuf = nameBuf;
this.pTInfo = pTInfo;
this.rgMemId = rgMemId;
this.pTInfo = new Pointer[pcFound];
this.rgMemId = new MEMBERID[pcFound];
this.pcFound = pcFound;
System.arraycopy(pTInfo, 0, this.pTInfo, 0, pcFound);
System.arraycopy(rgMemId, 0, this.rgMemId, 0, pcFound);
}

/**
Expand All @@ -446,12 +447,10 @@ public String getNameBuf() {
* @return the t info
*/
public ITypeInfo[] getTInfo() {

Pointer pVals = pTInfo.getValue();
ITypeInfo[] values=new ITypeInfo[pcFound];
for(int i=0;i<pcFound;i++)
{
values[i]=new TypeInfo(pVals.getPointer(i*Pointer.SIZE));
values[i]=new TypeInfo(pTInfo[i]);
}
return values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public String toString() {
}

public static class LPOLESTR extends PointerType {
public static class ByReference extends BSTR implements
public static class ByReference extends LPOLESTR implements
Structure.ByReference {
}

Expand Down
Loading