64-bit - 64 位 visio 上不支持无窗口 ActiveX 控件异常(exception)

标签 64-bit activex visio

我正在将应用程序的兼容性从 visio 32 位扩展到 visio 64 位。我在 win7(64) 机器上使用 visio 2013。我收到不支持无窗口 ActiveX 控件的异常。我都尝试过 KB 980533以及 Visi SDK 提供的自述示例文件,用于在此位置\VisSDK\Samples\Readme Samples 64bit.htm 构建 64 位系统的解决方案。我已经尝试过 DEP 解决方案但不起作用。

堆栈跟踪:

   at System.Windows.Forms.AxHost.EnsureWindowPresent()
   at System.Windows.Forms.AxHost.InPlaceActivate()
   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()

{“无法获取“AxDrawingControl”控件的窗口句柄。不支持无窗口 ActiveX 控件。”}

系统信息:

操作系统:Windows 7 64 位 Visio:Visio 2013 64 位 目标平台:.Net 4.5,任何CPU Interop:AxInterop.Microsoft.Office.VisOcx.dll(在32位机器上创建) Visio 绘图控件:VISOCX.DLL 64 位(是的,它已注册) IDE:Visual Studio 2013 专业版

最佳答案

我终于得到了可以在 64 位上运行的解决方案。

神奇的是,我意识到我实际上并不需要 XAML 中的控件;所以我最终做的是从 XAML 页面中删除控件,并从 .xaml.cs 代码的构造函数中实例化它。

所以:请按照this link中的说明进行操作构建自定义控件。我认为您必须使用 64 位版本的 MSBuild.exe 进行构建,如 the link you provided 中所述。 。显然,只有在创建自定义控件时才需要这样做;我能够直接从 VS 构建解决方案(但当由 MSBuild 构建时它也可以正常工作,因此它也可以在自动构建中工作)。

创建自定义控件

  1. 在安装了 32 位 Visio 的构建环境中创建一个名为 VisioAxControl 的新自定义控件项目
  2. 在 VS Designer 中,将 Visio Drawing 控件从工具箱拖/放到 WindowsFormsHost 内的窗体中。您可能需要将此控件添加到工具箱(右键单击工具箱,“选择项目...”)。执行此步骤会导致 VS 创建(并添加引用)一个新的 DLL,即 AxMicrosoft.Office.Interop.VisOcx 类型的“Microsoft Visio 15.0 绘图控件类型库”。该 DLL 被放入项目下的/obj/Release 目录中,但如果您只需选择引用并将“Copy local”设置为“true”,则在构建时会将其复制到/bin。
  3. 打开代码隐藏并将控件的范围更改为 public并重构:将其重命名为 axDrawingControl1AxVisioControl (最重要的是,不要忘记 this.AxVisioControl.Name = "AxVisioControl"; )
  4. 构建项目来为最终的 x86/32 位解决方案构建创建 WPF 控件 DLL
  5. 对于您的 x86/32 位解决方案,请复制并引用 VisioAxControl.dllAxMicrosoft.Office.Interop.VisOcx.dll放入解决方案中某处的文件夹中。

    构建 64 位控件

  6. 在安装了 64 位 Visio 的构建环境中保存、复制/移动和打开自定义控件项目

  7. 将构建平台更改为 x64
  8. 打开管理员命令提示符,cd 到您的项目目录
  9. 运行MSBuild_Path\MSBuild.exe /p:Configuration=Release /p:Platform=x64 your_project_file_name (对我来说,MSBuild_Path 是 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe)用于构建自定义控件项目,以创建 WPF 控件 DLL 以在最终的 x64 解决方案构建中使用

包含在您的 64 位项目中

  1. 复制和引用 /bin/Release/VisioAxControl.dll/obj/Release/AxMicrosoft.Office.Interop.VisOcx.dll .
  2. 在表单的 XAML 中,添加 <WindowsFormsHost name="MyWindowsFormsHost"></WindowsFormsHost>控制。
  3. 在 XAML 的代码隐藏中,在构造函数中:

    using VisioAxControl;
    public DesignView()
    {
        InitializeComponent();
        var avc = new VisioAxControl() { Name = "vControl" };
        this.MyWindowsFormsHost.Child = avc;
        this._avc = avc.AxVisioControl;  // for later reference, such as adding shapes
    }
    
  4. 保存并构建您的项目!

关于64-bit - 64 位 visio 上不支持无窗口 ActiveX 控件异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16167973/

相关文章:

delphi - 是否可以从 32 位应用程序访问 64 位 dll?

html - 在 activeX 对象上放置一个 div

c++ - 关于MFC开发的一些问题?

excel - 复制visio页面并将其作为图像粘贴到excel中

entity-framework - 在 x64 项目中启用迁移获取 System.BadImageFormatException

asp.net - 使用 IIS7.5 在 64 位 Windows 上运行 x86 Asp.net 应用程序时出现问题

multithreading - VB6 ActiveX 对象的多个实例

c# - 获取 Visio 主题颜色

visio - 如何知道 Visio 形状属于哪个主控

windows - 在 cmake 中强制构建 x64 位