2 Replies Latest reply on Jun 19, 2017 12:39 PM by Vincent Li

    How to add the edrawings activeX control 2016/2017 to VB.NET ?

    Vincent Li

      Hi Friends,

       

      I can add the activeX control of edrawings(2010~2015), cause they are 32bit. However, not for the 2016 to 2017. I tried it as the screen capture shows, but could never make it. I think it should be the issue that they are 64bit files.

       

      pls help to provide a correct procedure to handle it. thanks a lot.

       

      regards

      Vincent

       

       

      edrawings activeX control of 2016or2017.jpg

        • Re: How to add the edrawings activeX control 2016/2017 to VB.NET ?
          Jeetendra Prasad

          Hi,

           

          VS, being 32bit, makes this a big pain for 64bit activex controls. For achieving that You need to add edrawing dynamically into your winform dialog. Here is the snippet of code:-

           

           

           

           

           

           

           

          edrawing control host wrapper class:

           

           

              partial class eDwHost : System.Windows.Forms.AxHost

              {

                  public eDwHost()

                      : base("{22945A69-1191-4DCF-9E6F-409BDE94D101}")

                  {

          InitializeComponent();

                  }

           

                  private dynamic ocx;

           

                  protected override void AttachInterfaces()

                  {

          base.AttachInterfaces();

           

                      try

                      {

                          if (IntPtr.Size == 8) //64 bit

                          {

                              // "Forced compiler error! This code can never work in 32-bit processes since it depends on an ActiveX contronl which is only available in 64-bit."

           

          this.ocx = (dynamic)base.GetOcx();

                          }

                      }

          catch(Exception ex)

                      {

                          MessageBox.Show(ex.Message + "\r\n\r\n" + ex.StackTrace, "Exception loading eModelViewControl");

                      }

           

                  }

           

           

                  public new dynamic GetOcx()

                  {

                      return (dynamic)base.GetOcx();

                  }

              }

           

           

           

           

           

           

          And in your winform code :-

          eDwHost hostContainer = new eDwHost();

          giveproperties to hostContainer

          //((Control)hostContainer).Location // NOTE : base class is Control

          //hostContainer.Size// NOTE : base class is Control

          //hostContainer.AutoSize// NOTE : base class is Control

          //hostContainer..Enabled// NOTE : base class is Control

           

          To Add in winform:-

          objForm.AddControl(hostContainer);

           

          To get edrawing for apis:-

          dynamic emvControl = hostContainer.GetOcx();

          emvControl.OpenDoc(sViewFilePath, false, false, true, "");

           

           

           

           

          Please note that I have got this from SW forum only. If you get the original post then add links to them also.

           

           

           

           

          BTW : If you want try out Edrawing code for test and trial purpose then you can use it in your VBA7 editor (e.g. 64Bit excel VBA or Solidworks VBA). This makes trial code work faster as you can add then using VBA7 IDE and once you are confident then add same code in your main project in visual studio. Thats how I do it myself.

           

          FYI: VS development team doesnt want to make VS in 64 bit in near future.

           

           

          Regards,

          Jeetendra Prasad