Skip to content

Commit d7f91f1

Browse files
author
Lauri W Ahonen
committed
REFIID in MSDN is defined as IID &, and IID is defined as GUID. Not sure why all of these had REFIID.ByValue, as it a) doesn't work b) crashes the JVM with invalid memory access
1 parent f3e30cd commit d7f91f1

15 files changed

Lines changed: 139 additions & 46 deletions

contrib/platform/src/com/sun/jna/platform/win32/COM/COMBindingBaseObject.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public COMBindingBaseObject(CLSID clsid, boolean useActiveInstance,
8686

8787
if (COMUtils.SUCCEEDED(hr)) {
8888
this.iUnknown = new Unknown(this.pUnknown.getValue());
89-
hr = iUnknown.QueryInterface(new REFIID.ByValue( IDispatch.IID_IDISPATCH),
89+
hr = iUnknown.QueryInterface(new REFIID( IDispatch.IID_IDISPATCH),
9090
this.pDispatch);
9191
} else {
9292
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext,
@@ -129,7 +129,7 @@ public COMBindingBaseObject(String progId, boolean useActiveInstance,
129129

130130
if (COMUtils.SUCCEEDED(hr)) {
131131
this.iUnknown = new Unknown(this.pUnknown.getValue());
132-
hr = iUnknown.QueryInterface(new REFIID.ByValue(IDispatch.IID_IDISPATCH),
132+
hr = iUnknown.QueryInterface(new REFIID(IDispatch.IID_IDISPATCH),
133133
this.pDispatch);
134134
} else {
135135
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, dwClsContext,
@@ -211,7 +211,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult,
211211
DISPIDByReference pdispID = new DISPIDByReference();
212212

213213
// Get DISPID for name passed...
214-
HRESULT hr = pDisp.GetIDsOfNames(new REFIID.ByValue(Guid.IID_NULL), ptName, 1,
214+
HRESULT hr = pDisp.GetIDsOfNames(new REFIID(Guid.IID_NULL), ptName, 1,
215215
LOCALE_USER_DEFAULT, pdispID);
216216

217217
COMUtils.checkRC(hr);
@@ -263,7 +263,7 @@ protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult,
263263
}
264264

265265
// Make the call!
266-
HRESULT hr = pDisp.Invoke(dispId, new REFIID.ByValue(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT,
266+
HRESULT hr = pDisp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT,
267267
new WinDef.WORD(nType), dp, pvResult, pExcepInfo, puArgErr);
268268

269269
COMUtils.checkRC(hr, pExcepInfo, puArgErr);

contrib/platform/src/com/sun/jna/platform/win32/COM/COMEarlyBindingObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected void setProperty(DISPID dispId, boolean value) {
5959
}
6060

6161
@Override
62-
public HRESULT QueryInterface(REFIID.ByValue riid, PointerByReference ppvObject) {
62+
public HRESULT QueryInterface(REFIID riid, PointerByReference ppvObject) {
6363
return this.getIDispatch().QueryInterface(riid, ppvObject);
6464
}
6565

@@ -85,14 +85,14 @@ public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid,
8585
}
8686

8787
@Override
88-
public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames,
88+
public HRESULT GetIDsOfNames(REFIID riid, WString[] rgszNames, int cNames,
8989
LCID lcid, DISPIDByReference rgDispId) {
9090
return this.getIDispatch().GetIDsOfNames(riid, rgszNames, cNames, lcid,
9191
rgDispId);
9292
}
9393

9494
@Override
95-
public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid,
95+
public HRESULT Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
9696
WORD wFlags, DISPPARAMS.ByReference pDispParams,
9797
VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo,
9898
IntByReference puArgErr) {

contrib/platform/src/com/sun/jna/platform/win32/COM/Dispatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid,
9999
* the rg disp id
100100
* @return the hresult
101101
*/
102-
public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames,
102+
public HRESULT GetIDsOfNames(REFIID riid, WString[] rgszNames, int cNames,
103103
LCID lcid, DISPIDByReference rgDispId) {
104104
return (HRESULT) this._invokeNativeObject(5,
105105
new Object[] { this.getPointer(), riid, rgszNames, cNames,
@@ -127,7 +127,7 @@ public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cName
127127
* the pu arg err
128128
* @return the hresult
129129
*/
130-
public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid,
130+
public HRESULT Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
131131
WORD wFlags, DISPPARAMS.ByReference pDispParams,
132132
VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo,
133133
IntByReference puArgErr) {

contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected DispatchVTable.ByReference constructVTable() {
5454
protected void initVTable(final IDispatchCallback callback) {
5555
this.vtbl.QueryInterfaceCallback = new DispatchVTable.QueryInterfaceCallback() {
5656
@Override
57-
public HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject) {
57+
public HRESULT invoke(Pointer thisPointer, REFIID refid, PointerByReference ppvObject) {
5858
return callback.QueryInterface(refid, ppvObject);
5959
}
6060
};
@@ -84,14 +84,14 @@ public HRESULT invoke(Pointer thisPointer, UINT iTInfo, LCID lcid, PointerByRefe
8484
};
8585
this.vtbl.GetIDsOfNamesCallback = new DispatchVTable.GetIDsOfNamesCallback() {
8686
@Override
87-
public HRESULT invoke(Pointer thisPointer, REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid,
87+
public HRESULT invoke(Pointer thisPointer, REFIID riid, WString[] rgszNames, int cNames, LCID lcid,
8888
DISPIDByReference rgDispId) {
8989
return callback.GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
9090
}
9191
};
9292
this.vtbl.InvokeCallback = new DispatchVTable.InvokeCallback() {
9393
@Override
94-
public HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags,
94+
public HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
9595
DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo,
9696
IntByReference puArgErr) {
9797

contrib/platform/src/com/sun/jna/platform/win32/COM/DispatchVTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected List<String> getFieldOrder() {
5757
}
5858

5959
public static interface QueryInterfaceCallback extends StdCallLibrary.StdCallCallback {
60-
WinNT.HRESULT invoke(Pointer thisPointer, REFIID.ByValue refid, PointerByReference ppvObject);
60+
WinNT.HRESULT invoke(Pointer thisPointer, REFIID refid, PointerByReference ppvObject);
6161
}
6262

6363
public static interface AddRefCallback extends StdCallLibrary.StdCallCallback {
@@ -77,12 +77,12 @@ public static interface GetTypeInfoCallback extends StdCallLibrary.StdCallCallba
7777
}
7878

7979
public static interface GetIDsOfNamesCallback extends StdCallLibrary.StdCallCallback {
80-
WinNT.HRESULT invoke(Pointer thisPointer, REFIID.ByValue riid, WString[] rgszNames, int cNames, LCID lcid,
80+
WinNT.HRESULT invoke(Pointer thisPointer, REFIID riid, WString[] rgszNames, int cNames, LCID lcid,
8181
DISPIDByReference rgDispId);
8282
}
8383

8484
public static interface InvokeCallback extends StdCallLibrary.StdCallCallback {
85-
WinNT.HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID.ByValue riid, LCID lcid, WORD wFlags,
85+
WinNT.HRESULT invoke(Pointer thisPointer, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
8686
DISPPARAMS.ByReference pDispParams, VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo,
8787
IntByReference puArgErr);
8888
}

contrib/platform/src/com/sun/jna/platform/win32/COM/IDispatch.java

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,113 @@
3131
// TODO: Auto-generated Javadoc
3232
/**
3333
* Wrapper class for the IDispatch interface
34-
*
34+
*
3535
* IDispatch.GetTypeInfoCount 12 IDispatch.GetTypeInfo 16
3636
* IDispatch.GetIDsOfNames 20 IDispatch.Invoke 24
37-
*
37+
*
3838
* @author Tobias Wolf, [email protected]
3939
*/
4040
public interface IDispatch extends IUnknown {
4141

4242
public final static IID IID_IDISPATCH = new IID(
4343
"00020400-0000-0000-C000-000000000046");
4444

45+
/**
46+
* Retrieves the number of type information interfaces that an object provides (either 0 or 1).
47+
*
48+
* @param pctinfo The number of type information interfaces provided by the object. If the object provides type information, this number is 1; otherwise the number is 0.
49+
* @return This method can return one of these values.
50+
* S_OK
51+
* Success.
52+
* E_NOTIMPL
53+
* Failure.
54+
*/
4555
public HRESULT GetTypeInfoCount(UINTByReference pctinfo);
4656

57+
/**
58+
* Retrieves the type information for an object, which can then be used to get the type information for an interface.
59+
*
60+
* @param iTInfo The type information to return. Pass 0 to retrieve type information for the IDispatch implementation.
61+
* @param lcid The locale identifier for the type information.
62+
* An object may be able to return different type information for different languages. This is important
63+
* for classes that support localized member names. For classes that do not support localized member names,
64+
* this parameter can be ignored.
65+
* @param ppTInfo The requested type information object.
66+
* @return S_OK
67+
* Success.
68+
* DISP_E_BADINDEX
69+
* The iTInfo parameter was not 0.
70+
*/
4771
public HRESULT GetTypeInfo(UINT iTInfo, LCID lcid,
4872
PointerByReference ppTInfo);
4973

50-
public HRESULT GetIDsOfNames(REFIID.ByValue riid, WString[] rgszNames, int cNames,
74+
/**
75+
* Maps a single member and an optional set of argument names to a corresponding set of integer DISPIDs, which can be used
76+
* on subsequent calls to Invoke. The dispatch function DispGetIDsOfNames provides a standard implementation of GetIDsOfNames.
77+
*
78+
* @param riid Reserved for future use. Must be IID_NULL.
79+
* @param rgszNames The array of names to be mapped.
80+
* @param cNames The count of the names to be mapped.
81+
* @param lcid The locale context in which to interpret the names.
82+
* @param rgDispId Caller-allocated array, each element of which contains an identifier (ID) corresponding to one of the names passed in
83+
* the rgszNames array. The first element represents the member name. The subsequent elements represent each of the member's parameters.
84+
* @return
85+
*/
86+
public HRESULT GetIDsOfNames(REFIID riid, WString[] rgszNames, int cNames,
5187
LCID lcid, DISPIDByReference rgDispId);
5288

53-
public HRESULT Invoke(DISPID dispIdMember, REFIID.ByValue riid, LCID lcid,
89+
/**
90+
* Provides access to properties and methods exposed by an object. The dispatch function DispInvoke provides a standard implementation of Invoke.
91+
*
92+
* @param dispIdMember Identifies the member. Use GetIDsOfNames or the object's documentation to obtain the dispatch identifier.
93+
* @param riid Reserved for future use. Must be IID_NULL.
94+
* @param lcid The locale context in which to interpret arguments. The lcid is used by the GetIDsOfNames function, and is also
95+
* passed to Invoke to allow the object to interpret its arguments specific to a locale.
96+
* <p/>
97+
* Applications that do not support multiple national languages can ignore this parameter. For more information,
98+
* refer to Supporting Multiple National Languages and Exposing ActiveX Objects.
99+
* @param wFlags Flags describing the context of the Invoke call.
100+
* DISPATCH_METHOD
101+
* The member is invoked as a method. If a property has the same name, both this and the DISPATCH_PROPERTYGET flag can be set.
102+
* DISPATCH_PROPERTYGET
103+
* The member is retrieved as a property or data member.
104+
* DISPATCH_PROPERTYPUT
105+
* The member is changed as a property or data member.
106+
* DISPATCH_PROPERTYPUTREF
107+
* The member is changed by a reference assignment, rather than a value assignment. This flag is valid only when the property accepts a reference to an object.
108+
* @param pDispParams Pointer to a DISPPARAMS structure containing an array of arguments, an array of argument DISPIDs for named arguments, and counts for the number of elements in the arrays.
109+
* @param pVarResult Pointer to the location where the result is to be stored, or NULL if the caller expects no result. This argument is ignored if DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYPUTREF is specified.
110+
* @param pExcepInfo Pointer to a structure that contains exception information. This structure should be filled in if DISP_E_EXCEPTION is returned. Can be NULL.
111+
* @param puArgErr The index within rgvarg of the first argument that has an error. Arguments are stored in pDispParams->rgvarg in reverse order,
112+
* so the first argument is the one with the highest index in the array. This parameter is returned only when the resulting return
113+
* value is DISP_E_TYPEMISMATCH or DISP_E_PARAMNOTFOUND. This argument can be set to null. For details, see Returning Errors.
114+
* @return This method can return one of these values.
115+
* S_OK
116+
* Success.
117+
* DISP_E_BADPARAMCOUNT
118+
* The number of elements provided to DISPPARAMS is different from the number of arguments accepted by the method or property.
119+
* DISP_E_BADVARTYPE
120+
* One of the arguments in DISPPARAMS is not a valid variant type.
121+
* DISP_E_EXCEPTION
122+
* The application needs to raise an exception. In this case, the structure passed in pexcepinfo should be filled in.
123+
* DISP_E_MEMBERNOTFOUND
124+
* The requested member does not exist.
125+
* DISP_E_NONAMEDARGS
126+
* This implementation of IDispatch does not support named arguments.
127+
* DISP_E_OVERFLOW
128+
* One of the arguments in DISPPARAMS could not be coerced to the specified type.
129+
* DISP_E_PARAMNOTFOUND
130+
* One of the parameter IDs does not correspond to a parameter on the method. In this case, puArgErr is set to the first argument that contains the error.
131+
* DISP_E_TYPEMISMATCH
132+
* One or more of the arguments could not be coerced. The index of the first parameter with the incorrect type within rgvarg is returned in puArgErr.
133+
* DISP_E_UNKNOWNINTERFACE
134+
* The interface identifier passed in riid is not IID_NULL.
135+
* DISP_E_UNKNOWNLCID
136+
* The member being invoked interprets string arguments according to the LCID, and the LCID is not recognized. If the LCID is not needed to interpret arguments, this error should not be returned
137+
* DISP_E_PARAMNOTOPTIONAL
138+
* A required parameter was omitted.
139+
*/
140+
public HRESULT Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
54141
WORD wFlags, DISPPARAMS.ByReference pDispParams,
55142
VARIANT.ByReference pVarResult, EXCEPINFO.ByReference pExcepInfo,
56143
IntByReference puArgErr);

contrib/platform/src/com/sun/jna/platform/win32/COM/ITypeLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public HRESULT FindName(
7171
/* [annotation][out][in] */
7272
BSTRByReference szNameBuf,
7373
/* [in] */ULONG lHashVal,
74-
/* [length_is][size_is][out] */ITypeInfo[] ppTInfo,
74+
/* [length_is][size_is][out] */PointerByReference ppTInfo,
7575
/* [length_is][size_is][out] */MEMBERID[] rgMemId,
7676
/* [out][in] */USHORTByReference pcFound);
7777

contrib/platform/src/com/sun/jna/platform/win32/COM/IUnknown.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public interface IUnknown {
3232
public final static IID IID_IUNKNOWN = new IID(
3333
"{00000000-0000-0000-C000-000000000046}");
3434

35-
public HRESULT QueryInterface(REFIID.ByValue riid, PointerByReference ppvObject);
35+
public HRESULT QueryInterface(REFIID riid, PointerByReference ppvObject);
3636

3737
public int AddRef();
3838

contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public HRESULT FindName(
217217
/* [annotation][out][in] */
218218
BSTRByReference szNameBuf,
219219
/* [in] */ULONG lHashVal,
220-
/* [length_is][size_is][out] */ITypeInfo[] ppTInfo,
220+
/* [length_is][size_is][out] */PointerByReference ppTInfo,
221221
/* [length_is][size_is][out] */MEMBERID[] rgMemId,
222222
/* [out][in] */USHORTByReference pcFound) {
223223

contrib/platform/src/com/sun/jna/platform/win32/COM/TypeLibUtil.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package com.sun.jna.platform.win32.COM;
1414

15+
import com.sun.jna.Pointer;
1516
import com.sun.jna.WString;
1617
import com.sun.jna.platform.win32.Guid.CLSID;
1718
import com.sun.jna.platform.win32.Kernel32;
@@ -380,7 +381,7 @@ public FindName FindName(String name, int hashVal, short found) {
380381
COMUtils.checkRC(hr);
381382

382383
found = pcFound.getValue().shortValue();
383-
/* [length_is][size_is][out] */ITypeInfo[] ppTInfo = new ITypeInfo[found];
384+
/* [length_is][size_is][out] */PointerByReference ppTInfo = new PointerByReference();
384385
/* [length_is][size_is][out] */MEMBERID[] rgMemId = new MEMBERID[found];
385386
hr = this.typelib.FindName(szNameBuf, lHashVal, ppTInfo, rgMemId,
386387
pcFound);
@@ -404,7 +405,7 @@ public static class FindName {
404405
private String nameBuf;
405406

406407
/** The p t info. */
407-
private ITypeInfo[] pTInfo;
408+
private PointerByReference pTInfo;
408409

409410
/** The rg mem id. */
410411
private MEMBERID[] rgMemId;
@@ -414,18 +415,16 @@ public static class FindName {
414415

415416
/**
416417
* Instantiates a new find name.
417-
*
418-
* @param nameBuf
418+
* @param nameBuf
419419
* the name buf
420420
* @param pTInfo
421421
* the t info
422422
* @param rgMemId
423-
* the rg mem id
423+
* the rg mem id
424424
* @param pcFound
425-
* the pc found
426425
*/
427-
public FindName(String nameBuf, ITypeInfo[] pTInfo, MEMBERID[] rgMemId,
428-
short pcFound) {
426+
public FindName(String nameBuf, PointerByReference pTInfo, MEMBERID[] rgMemId,
427+
short pcFound) {
429428
this.nameBuf = nameBuf;
430429
this.pTInfo = pTInfo;
431430
this.rgMemId = rgMemId;
@@ -447,7 +446,14 @@ public String getNameBuf() {
447446
* @return the t info
448447
*/
449448
public ITypeInfo[] getTInfo() {
450-
return pTInfo;
449+
450+
Pointer pVals = pTInfo.getValue();
451+
ITypeInfo[] values=new ITypeInfo[pcFound];
452+
for(int i=0;i<pcFound;i++)
453+
{
454+
values[i]=new TypeInfo(pVals.getPointer(i*Pointer.SIZE));
455+
}
456+
return values;
451457
}
452458

453459
/**

0 commit comments

Comments
 (0)