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

📄 oleautomation.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	return (result == OLE.S_OK) ? pVarResult : null;}/** * Returns the value of the property specified by the dispIdMember. * * @param dispIdMember the ID of the property as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. *  * @return the value of the property specified by the dispIdMember or null *  * @since 2.0 */public Variant getProperty(int dispIdMember, Variant[] rgvarg) {	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, COM.DISPATCH_PROPERTYGET, rgvarg, null, pVarResult);	return (result == OLE.S_OK) ? pVarResult : null;	}/** * Returns the value of the property specified by the dispIdMember. * * @param dispIdMember the ID of the property as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. *  * @param rgdispidNamedArgs an array of identifiers for the arguments specified in rgvarg; the *        parameter IDs must be in the same order as their corresponding values; *        all arguments must have an identifier - identifiers can be obtained using  *        OleAutomation.getIDsOfNames *  * @return the value of the property specified by the dispIdMember or null *  * @since 2.0 */public Variant getProperty(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs) {	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, COM.DISPATCH_PROPERTYGET, rgvarg, rgdispidNamedArgs, pVarResult);	return (result == OLE.S_OK) ? pVarResult : null;}/**  * Invokes a method on the OLE Object; the method has no parameters. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @return the result of the method or null if the method failed to give result information */public Variant invoke(int dispIdMember) {	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, null, null, pVarResult);	return (result == COM.S_OK) ? pVarResult : null;}/**  * Invokes a method on the OLE Object; the method has no optional parameters. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. * * @return the result of the method or null if the method failed to give result information */public Variant invoke(int dispIdMember, Variant[] rgvarg) {	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, rgvarg, null, pVarResult);	return (result == COM.S_OK) ? pVarResult : null;}/**  * Invokes a method on the OLE Object; the method has optional parameters.  It is not * neccessary to specify all the optional parameters, only include the parameters for which * you are providing values. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. * * @param rgdispidNamedArgs an array of identifiers for the arguments specified in rgvarg; the *        parameter IDs must be in the same order as their corresponding values; *        all arguments must have an identifier - identifiers can be obtained using  *        OleAutomation.getIDsOfNames * * @return the result of the method or null if the method failed to give result information */public Variant invoke(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs) {	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, rgvarg, rgdispidNamedArgs, pVarResult);	return (result == COM.S_OK) ? pVarResult : null;}private int invoke(int dispIdMember, int wFlags, Variant[] rgvarg, int[] rgdispidNamedArgs, Variant pVarResult) {	// get the IDispatch interface for the control	if (objIDispatch == null) return COM.E_FAIL;		// create a DISPPARAMS structure for the input parameters	DISPPARAMS pDispParams = new DISPPARAMS();	// store arguments in rgvarg	if (rgvarg != null && rgvarg.length > 0) {		pDispParams.cArgs = rgvarg.length;		pDispParams.rgvarg = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, Variant.sizeof * rgvarg.length);		int offset = 0;		for (int i = rgvarg.length - 1; i >= 0 ; i--) {			rgvarg[i].getData(pDispParams.rgvarg + offset);			offset += Variant.sizeof;		}	}	// if arguments have ids, store the ids in rgdispidNamedArgs	if (rgdispidNamedArgs != null && rgdispidNamedArgs.length > 0) {		pDispParams.cNamedArgs = rgdispidNamedArgs.length;		pDispParams.rgdispidNamedArgs = OS.GlobalAlloc(COM.GMEM_FIXED | COM.GMEM_ZEROINIT, 4 * rgdispidNamedArgs.length);		int offset = 0;		for (int i = rgdispidNamedArgs.length; i > 0; i--) {			COM.MoveMemory(pDispParams.rgdispidNamedArgs + offset, new int[] {rgdispidNamedArgs[i-1]}, 4);			offset += 4;		}	}	// invoke the method	EXCEPINFO excepInfo = new EXCEPINFO();	int[] pArgErr = new int[1];	int pVarResultAddress = 0;	if (pVarResult != null)	pVarResultAddress = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);	int result = objIDispatch.Invoke(dispIdMember, new GUID(), COM.LOCALE_USER_DEFAULT, wFlags, pDispParams, pVarResultAddress, excepInfo, pArgErr);	if (pVarResultAddress != 0){		pVarResult.setData(pVarResultAddress);		COM.VariantClear(pVarResultAddress);		OS.GlobalFree(pVarResultAddress);	}		// free the Dispparams resources	if (pDispParams.rgdispidNamedArgs != 0){		OS.GlobalFree(pDispParams.rgdispidNamedArgs);	}	if (pDispParams.rgvarg != 0) {		int offset = 0;		for (int i = 0, length = rgvarg.length; i < length; i++){			COM.VariantClear(pDispParams.rgvarg + offset);			offset += Variant.sizeof;		}		OS.GlobalFree(pDispParams.rgvarg);	}	// save error string and cleanup EXCEPINFO	manageExcepinfo(result, excepInfo);			return result;}/**  * Invokes a method on the OLE Object; the method has no parameters.  In the early days of OLE,  * the IDispatch interface was not well defined and some applications (mainly Word) did not support  * a return value.  For these applications, call this method instead of calling * <code>public void invoke(int dispIdMember)</code>. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @exception SWTError <ul> *		<li>ERROR_ACTION_NOT_PERFORMED when method invocation fails *	</ul> */public void invokeNoReply(int dispIdMember) {	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, null, null, null);	if (result != COM.S_OK)		OLE.error(OLE.ERROR_ACTION_NOT_PERFORMED, result);}/**  * Invokes a method on the OLE Object; the method has no optional parameters.  In the early days of OLE,  * the IDispatch interface was not well defined and some applications (mainly Word) did not support  * a return value.  For these applications, call this method instead of calling * <code>public void invoke(int dispIdMember, Variant[] rgvarg)</code>. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. * * @exception SWTError <ul> *		<li>ERROR_ACTION_NOT_PERFORMED when method invocation fails *	</ul> */public void invokeNoReply(int dispIdMember, Variant[] rgvarg) {	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, rgvarg, null, null);	if (result != COM.S_OK)		OLE.error(OLE.ERROR_ACTION_NOT_PERFORMED, result);}/**  * Invokes a method on the OLE Object; the method has optional parameters.  It is not * neccessary to specify all the optional parameters, only include the parameters for which * you are providing values.  In the early days of OLE, the IDispatch interface was not well  * defined and some applications (mainly Word) did not support a return value.  For these  * applications, call this method instead of calling * <code>public void invoke(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs)</code>. * * @param dispIdMember the ID of the method as specified by the IDL of the ActiveX Control; the *        value for the ID can be obtained using OleAutomation.getIDsOfNames * * @param rgvarg an array of arguments for the method.  All arguments are considered to be *        read only unless the Variant is a By Reference Variant type. * * @param rgdispidNamedArgs an array of identifiers for the arguments specified in rgvarg; the *        parameter IDs must be in the same order as their corresponding values; *        all arguments must have an identifier - identifiers can be obtained using  *        OleAutomation.getIDsOfNames * * @exception SWTError <ul> *		<li>ERROR_ACTION_NOT_PERFORMED when method invocation fails *	</ul> */public void invokeNoReply(int dispIdMember, Variant[] rgvarg, int[] rgdispidNamedArgs) {	int result = invoke(dispIdMember, COM.DISPATCH_METHOD, rgvarg, rgdispidNamedArgs, null);	if (result != COM.S_OK)		OLE.error(OLE.ERROR_ACTION_NOT_PERFORMED, result);}private void manageExcepinfo(int hResult, EXCEPINFO excepInfo) {	if (hResult == COM.S_OK){		exceptionDescription = new String("No Error"); //$NON-NLS-1$		return;	}	// extract exception info	if (hResult == COM.DISP_E_EXCEPTION) {		if (excepInfo.bstrDescription != 0){			int size = COM.SysStringByteLen(excepInfo.bstrDescription);			char[] buffer = new char[(size + 1) /2];			COM.MoveMemory(buffer, excepInfo.bstrDescription, size);			exceptionDescription = new String(buffer);		} else {			exceptionDescription = new String("OLE Automation Error Exception "); //$NON-NLS-1$			if (excepInfo.wCode != 0){				exceptionDescription += "code = "+excepInfo.wCode; //$NON-NLS-1$			} else if (excepInfo.scode != 0){				exceptionDescription += "code = "+excepInfo.scode; //$NON-NLS-1$			}		}	} else {		exceptionDescription = new String("OLE Automation Error HResult : "+hResult); //$NON-NLS-1$	}	// cleanup EXCEPINFO struct	if (excepInfo.bstrDescription != 0)		COM.SysFreeString(excepInfo.bstrDescription);	if (excepInfo.bstrHelpFile != 0)		COM.SysFreeString(excepInfo.bstrHelpFile);	if (excepInfo.bstrSource != 0)		COM.SysFreeString(excepInfo.bstrSource);}/** * Sets the property specified by the dispIdMember to a new value. * * @param dispIdMember the ID of the property as specified by the IDL of the ActiveX Control; the *                     value for the ID can be obtained using OleAutomation.getIDsOfNames * @param rgvarg the new value of the property * * @return true if the operation was successful */public boolean setProperty(int dispIdMember, Variant rgvarg) {	Variant[] rgvarg2 = new Variant[] {rgvarg};	int[] rgdispidNamedArgs = new int[] {COM.DISPID_PROPERTYPUT};	int dwFlags = COM.DISPATCH_PROPERTYPUT;	if ((rgvarg.getType() & COM.VT_BYREF) == COM.VT_BYREF)		dwFlags = COM.DISPATCH_PROPERTYPUTREF;	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, dwFlags, rgvarg2, rgdispidNamedArgs, pVarResult);	return (result == COM.S_OK);}/** * Sets the property specified by the dispIdMember to a new value. * * @param dispIdMember the ID of the property as specified by the IDL of the ActiveX Control; the *                     value for the ID can be obtained using OleAutomation.getIDsOfNames * @param rgvarg an array of arguments for the method.  All arguments are considered to be *                     read only unless the Variant is a By Reference Variant type. * * @return true if the operation was successful * * @since 2.0 */public boolean setProperty(int dispIdMember, Variant[] rgvarg) {	int[] rgdispidNamedArgs = new int[] {COM.DISPID_PROPERTYPUT};	int dwFlags = COM.DISPATCH_PROPERTYPUT;	for (int i = 0; i < rgvarg.length; i++) {		if ((rgvarg[i].getType() & COM.VT_BYREF) == COM.VT_BYREF)		dwFlags = COM.DISPATCH_PROPERTYPUTREF;	}	Variant pVarResult = new Variant();	int result = invoke(dispIdMember, dwFlags, rgvarg, rgdispidNamedArgs, pVarResult);	return (result == COM.S_OK);}}

⌨️ 快捷键说明

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