⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oleclientsite.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
							fileInput.close();							stream.Release();							storage.Release();							OLE.error(OLE.ERROR_CANNOT_OPEN_FILE, result);						}					}					fileInput.close();					stream.Commit(COM.STGC_DEFAULT);					stream.Release();				} catch (IOException err) {					stream.Release();					storage.Release();					OLE.error(OLE.ERROR_CANNOT_OPEN_FILE);				}			}						// Open a temporary storage object			tempStorage = createTempStorage();			// Copy over contents of file			int result = storage.CopyTo(0, null, null, tempStorage.getAddress());			storage.Release();			if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_OPEN_FILE, result);			// create ole client			int[] ppv = new int[1];			result = COM.CoCreateInstance(appClsid, 0, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER, COM.IIDIUnknown, ppv);			if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);			objIUnknown = new IUnknown(ppv[0]);			// get the persistant storage of the ole client			ppv = new int[1];			result = objIUnknown.QueryInterface(COM.IIDIPersistStorage, ppv);			if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);			IPersistStorage iPersistStorage = new IPersistStorage(ppv[0]);			// load the contents of the file into the ole client site			result = iPersistStorage.Load(tempStorage.getAddress());			iPersistStorage.Release();			if (result != COM.S_OK)OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);		}				// Init sinks		addObjectReferences();				if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state = STATE_RUNNING;			} catch (SWTException e) {		dispose();		disposeCOMInterfaces();		throw e;	}}protected void addObjectReferences() {	//	int[] ppvObject = new int[1];	if (objIUnknown.QueryInterface(COM.IIDIPersist, ppvObject) == COM.S_OK) {		IPersist objIPersist = new IPersist(ppvObject[0]);		GUID tempid = new GUID();		if (objIPersist.GetClassID(tempid) == COM.S_OK)			objClsid = tempid;		objIPersist.Release();	}		//	ppvObject = new int[1];	int result = objIUnknown.QueryInterface(COM.IIDIViewObject2, ppvObject);	if (result != COM.S_OK)		OLE.error(OLE.ERROR_INTERFACE_NOT_FOUND, result);	objIViewObject2 = new IViewObject2(ppvObject[0]);	objIViewObject2.SetAdvise(aspect, 0, iAdviseSink.getAddress());	//	ppvObject = new int[1];	result = objIUnknown.QueryInterface(COM.IIDIOleObject, ppvObject);	if (result != COM.S_OK)		OLE.error(OLE.ERROR_INTERFACE_NOT_FOUND, result);	objIOleObject = new IOleObject(ppvObject[0]);	objIOleObject.SetClientSite(iOleClientSite.getAddress());	int[] pdwConnection = new int[1];	objIOleObject.Advise(iAdviseSink.getAddress(), pdwConnection);	objIOleObject.SetHostNames("main", "main");  //$NON-NLS-1$ //$NON-NLS-2$	// Notify the control object that it is embedded in an OLE container	COM.OleSetContainedObject(objIUnknown.getAddress(), true);	// Is OLE object linked or embedded?	ppvObject = new int[1];	if (objIUnknown.QueryInterface(COM.IIDIOleLink, ppvObject) == COM.S_OK) {		IOleLink objIOleLink = new IOleLink(ppvObject[0]);		int[] ppmk = new int[1];		if (objIOleLink.GetSourceMoniker(ppmk) == COM.S_OK) {			IMoniker objIMoniker = new IMoniker(ppmk[0]);			objIMoniker.Release();			type = COM.OLELINKED;			objIOleLink.BindIfRunning();		} else {			isStatic = true;		}		objIOleLink.Release();	}}protected int AddRef() {	refCount++;	return refCount;}private int CanInPlaceActivate() {	if (aspect == COM.DVASPECT_CONTENT && type == COM.OLEEMBEDDED)		return COM.S_OK;			return COM.S_FALSE;}private int ContextSensitiveHelp(int fEnterMode) {	return COM.S_OK;}protected void createCOMInterfaces() {		iUnknown = new COMObject(new int[]{2, 0, 0}){		public int method0(int[] args) {return QueryInterface(args[0], args[1]);}		public int method1(int[] args) {return AddRef();}		public int method2(int[] args) {return Release();}	};		iOleClientSite = new COMObject(new int[]{2, 0, 0, 0, 3, 1, 0, 1, 0}){		public int method0(int[] args) {return QueryInterface(args[0], args[1]);}		public int method1(int[] args) {return AddRef();}		public int method2(int[] args) {return Release();}		public int method3(int[] args) {return SaveObject();}		// method4 GetMoniker - not implemented		public int method5(int[] args) {return GetContainer(args[0]);}		public int method6(int[] args) {return ShowObject();}		public int method7(int[] args) {return OnShowWindow(args[0]);}		// method8 RequestNewObjectLayout - not implemented	};		iAdviseSink = new COMObject(new int[]{2, 0, 0, 2, 2, 1, 0, 0}){		public int method0(int[] args) {return QueryInterface(args[0], args[1]);}		public int method1(int[] args) {return AddRef();}		public int method2(int[] args) {return Release();}		public int method3(int[] args) {return OnDataChange(args[0], args[1]);}		public int method4(int[] args) {return OnViewChange(args[0], args[1]);}		//method5 OnRename - not implemented		public int method6(int[] args) {OnSave();return 0;}		public int method7(int[] args) {return OnClose();}		};		iOleInPlaceSite = new COMObject(new int[]{2, 0, 0, 1, 1, 0, 0, 0, 5, 1, 1, 0, 0, 0, 1}){		public int method0(int[] args) {return QueryInterface(args[0], args[1]);}		public int method1(int[] args) {return AddRef();}		public int method2(int[] args) {return Release();}		public int method3(int[] args) {return GetWindow(args[0]);}		public int method4(int[] args) {return ContextSensitiveHelp(args[0]);}		public int method5(int[] args) {return CanInPlaceActivate();}		public int method6(int[] args) {return OnInPlaceActivate();}		public int method7(int[] args) {return OnUIActivate();}		public int method8(int[] args) {return GetWindowContext(args[0], args[1], args[2], args[3], args[4]);}		public int method9(int[] args) {return Scroll(args[0]);}		public int method10(int[] args) {return OnUIDeactivate(args[0]);}		public int method11(int[] args) {return OnInPlaceDeactivate();}		// method12 DiscardUndoState - not implemented		// method13 DeactivateAndUndoChange - not implemented		public int method14(int[] args) {return OnPosRectChange(args[0]);}	};		iOleDocumentSite = new COMObject(new int[]{2, 0, 0, 1}){		public int method0(int[] args) {return QueryInterface(args[0], args[1]);}		public int method1(int[] args) {return AddRef();}		public int method2(int[] args) {return Release();}		public int method3(int[] args) {return ActivateMe(args[0]);}	};	}protected IStorage createTempStorage() {	int[] tempStorage = new int[1];	int grfMode = COM.STGM_READWRITE | COM.STGM_SHARE_EXCLUSIVE | COM.STGM_DELETEONRELEASE;	int result = COM.StgCreateDocfile(null, grfMode, 0, tempStorage);	if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_FILE, result);	return new IStorage(tempStorage[0]);}/** * Deactivates an active in-place object and discards the object's undo state. */public void deactivateInPlaceClient() {	if (objIOleInPlaceObject != null) {		objIOleInPlaceObject.InPlaceDeactivate();	}}private void deleteTempStorage() {	//Destroy this item's contents in the temp root IStorage.	if (tempStorage != null){		tempStorage.Release();	}	tempStorage = null;}protected void disposeCOMInterfaces() {	if (iUnknown != null)		iUnknown.dispose();	iUnknown = null;		if (iOleClientSite != null)	iOleClientSite.dispose();	iOleClientSite = null;		if (iAdviseSink != null)		iAdviseSink.dispose();	iAdviseSink = null;		if (iOleInPlaceSite != null)		iOleInPlaceSite.dispose();	iOleInPlaceSite = null;		if (iOleDocumentSite != null)		iOleDocumentSite.dispose();	iOleDocumentSite = null;}/** * Requests that the OLE Document or ActiveX Control perform an action; actions are almost always * changes to the activation state. * * @param verb the operation that is requested.  This is one of the OLE.OLEIVERB_ values * * @return an HRESULT value indicating the success of the operation request; OLE.S_OK indicates *         success */public int doVerb(int verb) {	// Not all OLE clients (for example PowerPoint) can be set into the running state in the constructor.	// The fix is to ensure that the client is in the running state before invoking any verb on it.	if (state == STATE_NONE) {		if (COM.OleRun(objIUnknown.getAddress()) == OLE.S_OK) state = STATE_RUNNING;	}		if (state == STATE_NONE || isStatic)		return COM.E_FAIL;		// See PR: 1FV9RZW	int result = objIOleObject.DoVerb(verb, null, iOleClientSite.getAddress(), 0, handle, null);	if (state != STATE_RUNNING && inInit) {		updateStorage();		inInit = false;	}	return result;}/** * Asks the OLE Document or ActiveX Control to execute a command from a standard  * list of commands. The OLE Document or ActiveX Control must support the IOleCommandTarget * interface.  The OLE Document or ActiveX Control does not have to support all the commands * in the standard list.  To check if a command is supported, you can call queryStatus with * the cmdID. * * @param cmdID the ID of a command; these are the OLE.OLECMDID_ values - a small set of common *              commands * @param options the optional flags; these are the OLE.OLECMDEXECOPT_ values * @param in the argument for the command * @param out the return value of the command * * @return an HRESULT value; OLE.S_OK is returned if successful * */public int exec(int cmdID, int options, Variant in, Variant out) {		if (objIOleCommandTarget == null) {		int[] address = new int[1];		if (objIUnknown.QueryInterface(COM.IIDIOleCommandTarget, address) != COM.S_OK)			return OLE.ERROR_INTERFACE_NOT_FOUND;		objIOleCommandTarget = new IOleCommandTarget(address[0]);	}		int inAddress = 0;	if (in != null){		inAddress = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);		in.getData(inAddress);	}	int outAddress = 0;	if (out != null){		outAddress = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);		out.getData(outAddress);	}			int result = objIOleCommandTarget.Exec(null, cmdID, options, inAddress, outAddress);		if (inAddress != 0){		COM.VariantClear(inAddress);		OS.GlobalFree(inAddress);	}	if (outAddress != 0) {		out.setData(outAddress);		COM.VariantClear(outAddress);		OS.GlobalFree(outAddress);	}			return result;}IDispatch getAutomationObject() {	int[] ppvObject = new int[1];	if (objIUnknown.QueryInterface(COM.IIDIDispatch, ppvObject) != COM.S_OK)		return null;	return new IDispatch(ppvObject[0]);}protected GUID getClassID(String clientName) {	// create a GUID struct to hold the result	GUID guid = new GUID();	// create a null terminated array of char	char[] buffer = null;	if (clientName != null) {		int count = clientName.length();		buffer = new char[count + 1];		clientName.getChars(0, count, buffer, 0);	}	if (COM.CLSIDFromProgID(buffer, guid) != COM.S_OK){		int result = COM.CLSIDFromString(buffer, guid);		if (result != COM.S_OK)			OLE.error(OLE.ERROR_INVALID_CLASSID, result);	}	return guid;}private int GetContainer(int ppContainer) {	/* Simple containers that do not support links to their embedded 	 * objects probably do not need to implement this method. Instead, 	 * they can return E_NOINTERFACE and set ppContainer to NULL.	 */	if (ppContainer != 0)		COM.MoveMemory(ppContainer, new int[]{0}, 4);	return COM.E_NOINTERFACE;}private SIZE getExtent() {	SIZE sizel = new SIZE();	// get the current size of the embedded OLENatives object	if (objIOleObject != null) {		if ( objIViewObject2 != null && !COM.OleIsRunning(objIOleObject.getAddress())) {			objIViewObject2.GetExtent(aspect, -1, null, sizel);		} else {			objIOleObject.GetExtent(aspect, sizel);		}	}	return xFormHimetricToPixels(sizel);}public Rectangle getIndent() {	return new Rectangle(indent.left, indent.right, indent.top, indent.bottom);}/** * Returns the program ID of the OLE Document or ActiveX Control. * * @return the program ID of the OLE Document or ActiveX Control

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -