2

我正在使用 Microsoft Outlook 视图控件,试图了解它的功能,但我并没有走得太远。它在设计时出现,但在运行时只给出“E_CLASSNOTREG”异常。我如何找出它在抱怨什么课程?

我刚刚创建了一个winform项目,将控件添加到工具箱中,然后将其拖到窗体中。我在设计时看到了我的 Outlook 收件箱。它添加了以下代码:

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
    System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
    this.axViewCtl1 = new AxMicrosoft.Office.Interop.OutlookViewCtl.AxViewCtl();
    ((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).BeginInit();
    this.SuspendLayout();
    // 
    // axViewCtl1
    // 
    this.axViewCtl1.Enabled = true;
    this.axViewCtl1.Location = new System.Drawing.Point(384, 184);
    this.axViewCtl1.Name = "axViewCtl1";
    this.axViewCtl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axViewCtl1.OcxState")));
    this.axViewCtl1.Size = new System.Drawing.Size(192, 192);
    this.axViewCtl1.TabIndex = 0;
    // 
    // Form1
    // 
    this.ClientSize = new System.Drawing.Size(1093, 633);
    this.Controls.Add(this.axViewCtl1);
    this.Name = "Form1";
    ((System.ComponentModel.ISupportInitialize)(this.axViewCtl1)).EndInit();
    this.ResumeLayout(false);
}

然后我运行它,它死在我身上:

System.Runtime.InteropServices.COMException occurred
  Message="Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
  Source="System.Windows.Forms"
  ErrorCode=-2147221164
  StackTrace:
       at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
       at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
       at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
       at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
       at System.Windows.Forms.AxHost.CreateInstance()
       at System.Windows.Forms.AxHost.GetOcxCreate()
       at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
       at System.Windows.Forms.AxHost.CreateHandle()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.AxHost.EndInit()
       at Sample.OutlookForm.Form1.InitializeComponent() in D:\source\tests\OutlookView\Sample.OutlookForm\Form1.Designer.cs:line 50
  InnerException: 

...例外是在 EndInit()。

另外,另一个奇怪的事情是,每次我在设计器中单击控件时,Visual Studio 都会冻结一段时间,有时短至 30 秒,有时我必须杀死 Outlook 任务才能让 VS 响应。

我在 Windows 7 x64 上运行带有最新补丁/SP 的 VS 2008,并且我有安装了所有最新补丁和服务包的 Office 2007。

为什么这在设计时对我有用,但在运行时却失败了?我怎样才能找到它正在寻找的未注册的内容?

4

2 回答 2

0

您是否有机会在 64 位机器上运行您的应用程序?我遇到了同样的问题,结果是 64 位与 Outlook ActiveX 控件不兼容。

如果不需要在本机 64 模式下运行您的应用程序,您可以修改您的程序以在 64 位机器上强制回退到 32 位兼容模式。这解决了我的问题。

您可以在构建解决方案时以 X86 平台为目标(推荐),也可以在之后使用corflags破解构建的可执行文件。

于 2012-02-08T10:13:14.823 回答
0

首先是一个快速的问题:您是如何获得工具栏上的控件的?在 ActiveX 控件中?

如果是这样,恐怕你无法使用它。该控件是为在 Outlook 中使用而开发的,它不是外部控件。

您可以使用多个第三方控件来模拟 Outlook 的外观,而无需采取此类措施。

于 2009-12-16T04:02:52.587 回答