From 44d04241b701a3760bfc388747d6cea8273f6b21 Mon Sep 17 00:00:00 2001 From: Veronika Irvine Date: Wed, 12 Jun 2002 20:28:12 +0000 Subject: Fix for 19925 --- .../org/eclipse/swt/ole/win32/OleClientSite.java | 16 +-- .../org/eclipse/swt/ole/win32/OleControlSite.java | 110 ++++++++++----------- 2 files changed, 65 insertions(+), 61 deletions(-) (limited to 'bundles/org.eclipse.swt/Eclipse SWT OLE Win32') diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java index b532d6e3c8..d620be06b7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java @@ -169,8 +169,11 @@ public OleClientSite(Composite parent, int style, File file) { char[] fileName = (file.getAbsolutePath()+"\0").toCharArray(); int result = COM.GetClassFile(fileName, appClsid); if (result != COM.S_OK) - OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result); - + OLE.error(OLE.ERROR_INVALID_CLASSID, result); + // associated CLSID may not be installed on this machine + if (getProgramID() == null) + OLE.error(OLE.ERROR_INVALID_CLASSID, result); + // Open a temporary storage object tempStorage = createTempStorage(); @@ -187,8 +190,8 @@ public OleClientSite(Composite parent, int style, File file) { if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state = STATE_RUNNING; } catch (SWTException e) { + dispose(); disposeCOMInterfaces(); - frame.Release(); throw e; } } @@ -236,8 +239,8 @@ public OleClientSite(Composite parent, int style, String progId) { if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state = STATE_RUNNING; } catch (SWTException e) { + dispose(); disposeCOMInterfaces(); - frame.Release(); throw e; } } @@ -350,8 +353,8 @@ public OleClientSite(Composite parent, int style, String progId, File file) { if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state = STATE_RUNNING; } catch (SWTException e) { + dispose(); disposeCOMInterfaces(); - frame.Release(); throw e; } } @@ -766,7 +769,8 @@ private int OnDataChange(int pFormatetc, int pStgmed) { } private void onDispose(Event e) { inDispose = true; - doVerb(OLE.OLEIVERB_DISCARDUNDOSTATE); + if (state != STATE_NONE) + doVerb(OLE.OLEIVERB_DISCARDUNDOSTATE); deactivateInPlaceClient(); releaseObjectInterfaces(); // Note, must release object interfaces before releasing frame deleteTempStorage(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleControlSite.java b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleControlSite.java index 76a607f4a4..ea52aa1586 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleControlSite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleControlSite.java @@ -75,68 +75,68 @@ public class OleControlSite extends OleClientSite */ public OleControlSite(Composite parent, int style, String progId) { super(parent, style); - - createCOMInterfaces(); - - // check for licensing - appClsid = getClassID(progId); - if (appClsid == null) OLE.error(OLE.ERROR_INVALID_CLASSID); - - int licinfo = getLicenseInfo(appClsid); - if (licinfo == 0) { - - // Open a storage object - tempStorage = createTempStorage(); - - // Create ole object with storage object - int[] address = new int[1]; - int result = COM.OleCreate(appClsid, COM.IIDIUnknown, COM.OLERENDER_DRAW, null, 0, tempStorage.getAddress(), address); - if (result != COM.S_OK) - OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result); - - objIUnknown = new IUnknown(address[0]); - - } else { - // Prepare the ClassFactory - int[] ppvObject = new int[1]; - try { - int result = COM.CoGetClassObject(appClsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject); - if (result != COM.S_OK) { - OLE.error(OLE.ERROR_CANNOT_ACCESS_CLASSFACTORY, result); + try { + createCOMInterfaces(); + + // check for licensing + appClsid = getClassID(progId); + if (appClsid == null) OLE.error(OLE.ERROR_INVALID_CLASSID); + + int licinfo = getLicenseInfo(appClsid); + if (licinfo == 0) { + + // Open a storage object + tempStorage = createTempStorage(); + + // Create ole object with storage object + int[] address = new int[1]; + int result = COM.OleCreate(appClsid, COM.IIDIUnknown, COM.OLERENDER_DRAW, null, 0, tempStorage.getAddress(), address); + if (result != COM.S_OK) + OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result); + + objIUnknown = new IUnknown(address[0]); + + } else { + // Prepare the ClassFactory + int[] ppvObject = new int[1]; + try { + int result = COM.CoGetClassObject(appClsid, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, 0, COM.IIDIClassFactory2, ppvObject); + if (result != COM.S_OK) { + OLE.error(OLE.ERROR_CANNOT_ACCESS_CLASSFACTORY, result); + } + IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]); + // Create Com Object + ppvObject = new int[1]; + result = classFactory.CreateInstanceLic(0, 0, COM.IIDIUnknown, licinfo, ppvObject); + classFactory.Release(); + if (result != COM.S_OK) + OLE.error(OLE.ERROR_CANNOT_CREATE_LICENSED_OBJECT, result); + } finally { + COM.SysFreeString(licinfo); } - IClassFactory2 classFactory = new IClassFactory2(ppvObject[0]); - // Create Com Object + + objIUnknown = new IUnknown(ppvObject[0]); + + // Prepare a storage medium ppvObject = new int[1]; - result = classFactory.CreateInstanceLic(0, 0, COM.IIDIUnknown, licinfo, ppvObject); - classFactory.Release(); - if (result != COM.S_OK) - OLE.error(OLE.ERROR_CANNOT_CREATE_LICENSED_OBJECT, result); - } finally { - COM.SysFreeString(licinfo); - } - - objIUnknown = new IUnknown(ppvObject[0]); - - // Prepare a storage medium - ppvObject = new int[1]; - if (objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppvObject) == COM.S_OK) { - IPersistStorage persist = new IPersistStorage(ppvObject[0]); - tempStorage = createTempStorage(); - persist.InitNew(tempStorage.getAddress()); - persist.Release(); + if (objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppvObject) == COM.S_OK) { + IPersistStorage persist = new IPersistStorage(ppvObject[0]); + tempStorage = createTempStorage(); + persist.InitNew(tempStorage.getAddress()); + persist.Release(); + } } - } - - // Init sinks - try { + + // Init sinks addObjectReferences(); + + if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state= STATE_RUNNING; + } catch (SWTError e) { + dispose(); disposeCOMInterfaces(); - frame.Release(); throw e; - } - - if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state= STATE_RUNNING; + } } /** * Adds the listener to receive events. -- cgit