user1238425
user1238425

Reputation: 31

Windowless ActiveX controls are not supported exception on 64Bit visio

I am extending the compatibility of my application from visio 32-bit to visio 64 bit. I am using visio 2013 on win7(64) machine. I am getting exception of windowless ActiveX control is not supported. I have tried both KB 980533 and Readme sample file provided with Visi SDK for buidling solution for 64-bit system on this location \VisSDK\Samples\Readme Samples 64bit.htm. I have tried DEP solution but not working.

STACK TRACE:

   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()

{"Unable to get the window handle for the 'AxDrawingControl' control. Windowless ActiveX controls are not supported."}

System Info:

OS: Windows 7 64 bit Visio: Visio 2013 64 bit Target Platform:.Net 4.5, Any CPU Interop: AxInterop.Microsoft.Office.VisOcx.dll (created on the 32 bit machine) Visio Drawing Control: VISOCX.DLL 64 bit (yes, it's registered) IDE: Visual Studio 2013 Professional

Upvotes: 2

Views: 2743

Answers (1)

klugerama
klugerama

Reputation: 3352

I finally got our solution to work using 64-bit.

The magic was that I realized that I didn't actually need the control in the XAML; so what I ended up doing was removing the control from the XAML page, and instantiating it from the constructor of the .xaml.cs code.

So: follow the instructions in this link to build a custom control. I think you have to build using the 64-bit version of MSBuild.exe as noted in the link you provided. This is apparently only required when you are creating the custom control; I was able to build the solution directly from VS (but it also worked correctly when built by MSBuild, so it works in automated builds, as well).

Creating a custom control

  1. Create a new custom control project named VisioAxControl in a build environment with 32-bit Visio installed
  2. In VS Designer, drag/drop the Visio Drawing control from the toolbox to the form, inside a WindowsFormsHost. You may need to add this control to the toolbox (right-click toolbox, "Choose items..."). Performing this step causes VS to create (and add a reference to) a new DLL, "Microsoft Visio 15.0 Drawing Control Type Library" of type AxMicrosoft.Office.Interop.VisOcx. This DLL is put into the /obj/Release directory under the project, but will be copied to /bin when you build if you simply select the reference and set "Copy local" to "true".
  3. Open the code-behind and change the scope of the control to public and refactor:rename it from axDrawingControl1 to AxVisioControl (most importantly, don't forget this.AxVisioControl.Name = "AxVisioControl";)
  4. Build the project to create the WPF control DLL for the final x86/32-bit solution build
  5. For your x86/32-bit solution, copy & reference both VisioAxControl.dll and AxMicrosoft.Office.Interop.VisOcx.dll into a folder somewhere in the solution.

    Building the 64-bit control

  6. Save, copy/move, and open the custom control project in a build environment with 64-bit Visio installed

  7. Change the build platform to x64
  8. Open an administrator command prompt, cd to your project directory
  9. Run MSBuild_Path\MSBuild.exe /p:Configuration=Release /p:Platform=x64 your_project_file_name (for me, MSBuild_Path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe) to build the custom control project to create the WPF control DLL for use in the final x64 solution build

Including in your 64-bit project

  1. Copy & reference /bin/Release/VisioAxControl.dll and /obj/Release/AxMicrosoft.Office.Interop.VisOcx.dll.
  2. In the XAML of your form, add a <WindowsFormsHost name="MyWindowsFormsHost"></WindowsFormsHost> control.
  3. In the code-behind of the XAML, in the constructor:

    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. Save & Build your project!

Upvotes: 2

Related Questions