private static void ShowErrorDialog(IUIService uiService, Exception ex, Control control) { if (uiService != null) { uiService.ShowError(ex); } else { string message = ex.Message; if (message == null || message.Length == 0) { message = ex.ToString(); } RTLAwareMessageBox.Show(control, message, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, 0); } }
/// <summary> /// <para>Creates an instance of the ActiveX control. Calls VS7 project system /// to generate the wrappers if they are needed..</para> /// </summary> protected override IComponent[] CreateComponentsCore(IDesignerHost host) { Debug.Assert(host != null, "Designer host is null!!!"); // Get the DTE References object // object references = GetReferences(host); if (references != null) { try { TYPELIBATTR tlibAttr = GetTypeLibAttr(); object[] args = new object[5]; args[0] = "{" + tlibAttr.guid.ToString() + "}"; args[1] = (int)tlibAttr.wMajorVerNum; args[2] = (int)tlibAttr.wMinorVerNum; args[3] = tlibAttr.lcid; args[4] = ""; object tlbRef = references.GetType().InvokeMember("AddActiveX", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, references, args, CultureInfo.InvariantCulture); Debug.Assert(tlbRef != null, "Null reference returned by AddActiveX (tlbimp) by the project system for: " + clsid); args[4] = "aximp"; object axRef = references.GetType().InvokeMember("AddActiveX", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, references, args, CultureInfo.InvariantCulture); Debug.Assert(axRef != null, "Null reference returned by AddActiveX (aximp) by the project system for: " + clsid); axctlType = GetAxTypeFromReference(axRef, host); } catch (TargetInvocationException tie) { Debug.WriteLineIf(AxToolSwitch.TraceVerbose, "Generating Ax References failed: " + tie.InnerException); throw tie.InnerException; } catch (Exception e) { Debug.WriteLineIf(AxToolSwitch.TraceVerbose, "Generating Ax References failed: " + e); throw; } } if (axctlType == null) { IUIService uiSvc = (IUIService)host.GetService(typeof(IUIService)); if (uiSvc == null) { RTLAwareMessageBox.Show(null, SR.AxImportFailed, null, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0); } else { uiSvc.ShowError(SR.AxImportFailed); } return(Array.Empty <IComponent>()); } var comps = new IComponent[1]; try { comps[0] = host.CreateComponent(axctlType); } catch (Exception e) { Debug.Fail("Could not create type: " + e); throw; } Debug.Assert(comps[0] != null, "Could not create instance of ActiveX control wrappers!!!"); return(comps); }