[commit] r1491 - in trunk/GME: Gme MgaUtil

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Aug 31 23:01:06 CDT 2011


Author: ksmyth
Date: Wed Aug 31 23:01:00 2011
New Revision: 1491

Log:
SetErrorInfo and return HRESULT from interpreter in MgaLauncher::RunComponent. GetErrorInfo in GME

Modified:
   trunk/GME/Gme/GMEView.cpp
   trunk/GME/MgaUtil/   (props changed)
   trunk/GME/MgaUtil/MgaLauncher.cpp
   trunk/GME/MgaUtil/MgaLauncher.h
   trunk/GME/MgaUtil/StdAfx.cpp
   trunk/GME/MgaUtil/StdAfx.h

Modified: trunk/GME/Gme/GMEView.cpp
==============================================================================
--- trunk/GME/Gme/GMEView.cpp	Wed Aug 31 22:58:17 2011	(r1490)
+++ trunk/GME/Gme/GMEView.cpp	Wed Aug 31 23:01:00 2011	(r1491)
@@ -8406,8 +8406,8 @@
 	GMEEVENTLOG_GUIFCOS(selected);
 	MSGTRY
 	{
-		CComObjPtr<IMgaLauncher> launcher;
-		COMTHROW( launcher.CoCreateInstance(L"Mga.MgaLauncher") );
+		IMgaLauncherPtr launcher;
+		COMTHROW( launcher.CreateInstance(L"Mga.MgaLauncher") );
 		if(!launcher) {
 			AfxMessageBox(_T("Cannot start up component launcher"));
 		}
@@ -8427,9 +8427,10 @@
 			}
 
 			if(theApp.bNoProtect) COMTHROW( launcher->put_Parameter(CComVariant(true)));
-			if(launcher->RunComponent(NULL, theApp.mgaProject, focus, selfcos, contextSelection ? GME_CONTEXT_START :  GME_BGCONTEXT_START) != S_OK) {
-				AfxMessageBox(_T("Component execution failed"));
-			}
+
+			MSGTRY {
+			launcher->__RunComponent(_bstr_t(), theApp.mgaProject, focus, selfcos, contextSelection ? GME_CONTEXT_START :  GME_BGCONTEXT_START);
+			} MSGCATCH(L"Component execution failed",;)
 		}
 	}
 	MSGCATCH(_T("Error while trying to run the interpreter"),;)

Modified: trunk/GME/MgaUtil/MgaLauncher.cpp
==============================================================================
--- trunk/GME/MgaUtil/MgaLauncher.cpp	Wed Aug 31 22:58:17 2011	(r1490)
+++ trunk/GME/MgaUtil/MgaLauncher.cpp	Wed Aug 31 23:01:00 2011	(r1491)
@@ -749,35 +749,31 @@
 			COMTHROW(registrar->get_ComponentExtraInfo(REGACCESS_PRIORITY, prgid, CComBSTR(L"ExecEngine"), &engine));
 			COMTHROW(registrar->get_ComponentExtraInfo(REGACCESS_PRIORITY, prgid, CComBSTR(L"ScriptFile"), &scriptfile));
 			if(!engine || !scriptfile) {
-				AfxMessageBox(_T("Incomplete registration for script component ")+ compname);
+				ThrowCOMError(E_FAIL, _T("Incomplete registration for script component ") + compname);
 			}
 			compname += _T(" (") + CString(engine) + _T(")");
 			COMTHROW( component.CoCreateInstance(engine) );
 			CComQIPtr<IMgaComponentEx> compex = component;
 			if(!compex) {
-				AfxMessageBox(_T("Exec.engine is only supported with extended component interface"));
-				COMRETURN(E_MGA_NOT_SUPPORTED);
+				ThrowCOMError(E_MGA_NOT_SUPPORTED, L"Exec.engine is only supported with extended component interface");
 			}
 			if(scriptfile) {
-				COMTHROW(compex->put_ComponentParameter(CComBSTR(L"script"), CComVariant(scriptfile)));
+				compex->ComponentParameter[_bstr_t(L"script")] = CComVariant(scriptfile);
 			}
 		}
 		else COMTHROW(CreateMgaComponent(component, prgid));  // Before DispatchProxy: COMTHROW(component.CoCreateInstance(prgid));
 
 
 		if(component == NULL) {
-			AfxMessageBox(CString(_T("Could not start component ")) + compname);
+			ThrowCOMError(E_FAIL, L"Could not start component '" + compname + "'");
 		}
 		else {
-			CComQIPtr<IGMEVersionInfo> vi = component;
+			IGMEVersionInfoPtr vi = (IMgaComponent*) component;
 			if(!vi) {
-					if(AfxMessageBox(	_T("This component does not provide interface version information\n")
-										_T("It is probably incompatible with GME\n")
-										_T("Do you want to proceed anyway?") , MB_YESNO) !=IDYES) return S_OK;
+				ThrowCOMError(E_NOINTERFACE, L"This component does not provide interface version information\n");
 			}
 			else {
-				GMEInterfaceVersion vv;
-				COMTHROW(vi->get_version(&vv));
+				GMEInterfaceVersion vv = vi->version;
 				if(vv != INTERFACE_VERSION) {
 					CString aa;
 					aa.Format(_T("The interface version number of this component (%d.%d) differs from the GME version (%d.%d)\n")
@@ -794,7 +790,7 @@
 					// Need to catch SEH exceptions (especially for Win7 x64: see GME-318)
 					if (SUCCEEDED(hr) && !InvokeExWithCrashRpt(compex, project, focusobj, selectedobjs, param, hr)) {
 						project->AbortTransaction();
-						AfxMessageBox(_T("An error has occurred in component ") + compname + _T(".\n")
+						ThrowCOMError(E_POINTER, _T("An error has occurred in component ") + compname + _T(".\n")
 							_T("GME may not be in a stable state.\n")
 							_T("Please save your work and restart GME."));
 					} else {
@@ -803,10 +799,9 @@
 							if (supportErrorInfo && GetErrorInfo(desc.GetAddress())) {
 								CString msg = static_cast<const TCHAR*>(desc);
 								msg = "Interpreter returned error: " + msg;
-								AfxMessageBox(msg, MB_OK | MB_ICONSTOP);
-								SysFreeString(desc);
+								ThrowCOMError(hr, msg);
 							} else {
-								DisplayError(_T("Interpreter returned error"), hr);
+								ThrowCOMError(hr, _T("Interpreter returned error"));
 							}
 						}
 						// Sometimes interpreters forget to close transactions, even when returning S_OK
@@ -830,7 +825,7 @@
 					}
 					catch(hresult_exception &e)	{
 						project->AbortTransaction();
-						DisplayError(_T("Interpreter returned error"), e.hr);
+						ThrowCOMError(e.hr, _T("Interpreter returned error"));
 					}
 					catch(...)
 					{
@@ -844,9 +839,9 @@
 			else {		// running unprotected
 				try	{
 					COMTHROW(component->Initialize(project));
-					CComQIPtr<IMgaComponentEx> compex = component;
+					IMgaComponentExPtr compex = (IMgaComponent*)component;
 					if(compex) {
-						COMTHROW(compex->InvokeEx(project, focusobj, CComQIPtr<IMgaFCOs>(selectedobjs), param));
+						compex->__InvokeEx(project, focusobj, CComQIPtr<IMgaFCOs>(selectedobjs), param);
 					}
 					else {
 						CComPtr<IMgaTerritory> terr;

Modified: trunk/GME/MgaUtil/MgaLauncher.h
==============================================================================
--- trunk/GME/MgaUtil/MgaLauncher.h	Wed Aug 31 22:58:17 2011	(r1490)
+++ trunk/GME/MgaUtil/MgaLauncher.h	Wed Aug 31 23:01:00 2011	(r1491)
@@ -57,6 +57,23 @@
 	STDMETHOD(RunComponent)(BSTR progid, IMgaProject *project, IMgaFCO *focusobj, IMgaFCOs *selectedobjs, long param);
 // ------- Helper functions
 
+	void ThrowCOMError(HRESULT hr, const wchar_t* err)
+	{
+		ICreateErrorInfoPtr errCreate;
+		if (SUCCEEDED(CreateErrorInfo(&errCreate))
+			&& SUCCEEDED(errCreate->SetDescription(const_cast<wchar_t*>(err)))
+			&& SUCCEEDED(errCreate->SetGUID(__uuidof(IMgaLauncher)))
+			)
+		{
+			IErrorInfoPtr errorInfo = errCreate;
+			if (errorInfo)
+			{
+				throw _com_error(hr, errorInfo.Detach());
+			}
+		}
+		throw _com_error(hr);
+	}
+
 public:
 	static CString PruneConnectionString(const CString &conn);
 };

Modified: trunk/GME/MgaUtil/StdAfx.cpp
==============================================================================
--- trunk/GME/MgaUtil/StdAfx.cpp	Wed Aug 31 22:58:17 2011	(r1490)
+++ trunk/GME/MgaUtil/StdAfx.cpp	Wed Aug 31 23:01:00 2011	(r1491)
@@ -11,6 +11,8 @@
 #endif
 
 #import "ParserLib.tlb" implementation_only auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
+#import "CoreLib.tlb" implementation_only auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
+#import "MgaLib.tlb" implementation_only auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
 
 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
 

Modified: trunk/GME/MgaUtil/StdAfx.h
==============================================================================
--- trunk/GME/MgaUtil/StdAfx.h	Wed Aug 31 22:58:17 2011	(r1490)
+++ trunk/GME/MgaUtil/StdAfx.h	Wed Aug 31 23:01:00 2011	(r1491)
@@ -60,6 +60,7 @@
 
 #define wireHWND HWND
 
+// Imports
 #import "CoreLib.tlb" no_implementation auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
 #import "MetaLib.tlb" no_implementation auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
 #import "MgaLib.tlb" no_implementation auto_search no_namespace no_search_namespace raw_method_prefix("") high_method_prefix("__")
@@ -82,6 +83,7 @@
 #define __MgaUtilLib_h__
 #define __Parser_h__
 #define __Gme_h__
+// End Imports
 
 ///////////////////////////////////////////////////////////////////
 


More information about the gme-commit mailing list