OK,
so this one really has me scratching my head.
Simple bit of code,
public static void main(String[] args) {
HRESULT hr = Ole32.INSTANCE.CoInitialize(null);
COMUtils.checkRC(hr);
// Get CLSID for Word.Application...
CLSID.ByReference clsid = new CLSID.ByReference();
hr = Ole32.INSTANCE.CLSIDFromProgID("Word.Application", clsid);
COMUtils.checkRC(hr);
PointerByReference pUnknown = new PointerByReference();
hr = Ole32.INSTANCE.CoCreateInstance(clsid, null, WTypes.CLSCTX_SERVER, IUnknown.IID_IUNKNOWN, pUnknown);
COMUtils.checkRC(hr);
Unknown unk = new Unknown(pUnknown.getValue());
PointerByReference ppvObject = new PointerByReference();
IID iid = IUnknown.IID_IUNKNOWN;
REFIID.ByValue ri = new REFIID.ByValue(iid);
hr = unk.QueryInterface(ri, ppvObject);
COMUtils.checkRC(hr);
}
Works fine on a 64 bit JVM on Windows 7 (64 bit OS).
If I run the same code on 32 bit JVM (Java 7 jdk) on Windows 7 (64 bit os), I get an error from COM when executing the 'QueryInterface' call at the end.
If I change the signature (or rather add a different temporary method QueryInterface2) to take a REFIID.ByReference insteead of a REFIID.ByValue,
the 32 bit version works, and the 64 bit version seems to work, although the new signature breaks if used in other places (i.e. the callback code).
Any clues as to what is going on here would be gratefully received.
The C++ signature is "QueryInterface(REFIID riid,void * *ppvObject)"
where REFIID is "#define REFIID const IID &"
IID is a typedef of GUID, which in turn is a struct.