* querying for typeInfo that occurs in the OleAutomation(IDispatch)
* constructor will cause a VM crash on some kinds of JavaScript objects,
* such as the window.alert function. So we do it by hand.
*/
IDispatch dispatch = variant.getDispatch();
Variant result = new Variant();
int pVarResultAddress = 0;
int globalRef = 0;
try {
pVarResultAddress = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
Variant.sizeof);
int[] pArgErr = new int[1];
int hr = dispatch.Invoke(IDispatchProxy.DISPID_MAGIC_GETGLOBALREF,
new GUID(), COM.LOCALE_USER_DEFAULT, COM.DISPATCH_METHOD,
new DISPPARAMS(), pVarResultAddress, new EXCEPINFO(), pArgErr);
if (hr >= COM.S_OK) {
result = Variant.win32_new(pVarResultAddress);
globalRef = result.getInt();
}
if (globalRef != 0) {
// This is really a Java object being passed back via an IDispatchProxy.
IDispatchProxy proxy = (IDispatchProxy) LowLevel.objFromGlobalRefInt(globalRef);
return proxy.getTarget();
}
return null;
} finally {
if (result != null) {
result.dispose();
}
if (pVarResultAddress != 0) {
COM.VariantClear(pVarResultAddress);
OS.GlobalFree(pVarResultAddress);
}