ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Mauricio Rojas Blog

November 2008 - Posts

  • Migration of ActiveX UserDocuments to C# or .NET

    This is an interesting workaround that you can use to support the migration of ActiveX Documents with the Artinsoft VBUM.

     

    DOWNLOAD TOOL 

    With this tool you can fix your projects, so they are supported by the the Artinsoft Migration Tool.

     

    Just run the tool like this:

    FixUserDocuments Project1.vbp

    This will generate a new project called Project1_modified.vbp. Migrate this new project and now UserDocuments will be supported.

     

     

    First Some History
     

    VB6 allows you to create UserDocuments, which can be embedded inside an ActiveX container. The most common one is Internet Explorer.

     

    After compilation, the document is contained in a Visual Basic Document file (.VBD) and the server is contained in either an .EXE or .DLL file.

    During development, the project is in a .DOB file, which is a plain text file containing the definitions of the project’s controls, source code, and so on.

    If an ActiveX document project contains graphical elements that cannot be stored in text format, they will be kept in a .DOX file.

    The .DOB and .DOX files in an ActiveX document project are parallel to the .FRM and .FRX files of a regular Visual Basic executable project.

     

    The trick to support ActiveX documents is that in general they are very similar to UserControls, and .NET UserControls can also be hosted in a WebBrowser.

     

    The following command line tool can be used to update your VB6 projects. It will generate a new solution where UserDocuments will be defined as UserControls.

     

    If you have an ActiveX document like the following:

     

     

    After running the tool you will have an Project like the following:

     

     

     

    Now migrate your project.

    And you get something like this:

     

     

    Copy the generated assemblies and .pdb to the directory you will publish:

     

    Create a Page lets say:

     

    UserDocument1.htm

    With contents like:

     

    <html>

    <body>

    <p>ActiveX Demo<br> <br></body>

    <object id="UserDocument1"

    classid="http:<AssemblyFileName>#<QualifiedName of Object>"

    height="500" width="500" VIEWASTEXT>   

    </object>

    <br><br>

    </html>

     

    For example:

    <html>

    <body>

    <p>ActiveX Demo<br> <br></body>

    <object id="UserDocument1"

    classid="http:Project1.dll#Project1.UserDocument1"

    height="500" width="500" VIEWASTEXT>   

    </object>

    <br><br>

    </html>

      

     

     

    Publish the output directory:

     

    1. Create a Virtual Directory:

    1. Name the directory as you want. For examples Project1

     

     

     

     

     

     

    1. Properties for the Virtual Directory will look like this:

     

    NOTE: to see this dialog right click over the virtual directory

     

    1. Now just browse to the address lets say http:\\localhost\Project1\UserDocument1.htm

     

     

     

     

    The colors are different because of the Host configuration however a simple CSS like:

     

    <style>

     body {background-color: gray;}

    </style>

     

    Can make the desired change:

     

     

     

    Notice that there will be security limitations, for example for thinks like MessageBoxes.

    You can allow restricted operations by setting your site as a restricted site:

     

    For example:

     

     

    Restrictions

    The constraints for this solution include:

     

    * This solutions requires Windows operating system on the client side

    * Internet Explorer 6.0 is the only browser that provides support for this type of hosting

    * It requires .NET runtime to be installed on the client machine.

    * It also requires Windows 2000 and IIS 5.0 or above on the server side

     

    Due to all of the above constraints, it might be beneficial to detect the capabilities of the client machine and then deliver content that is appropriate to them. For example, since forms controls hosted in IE require the presence of the .NET runtime on the client machine, we can write code to check if the client machine has the .NET runtime installed. You can do this by checking the value of the Request.Browser.ClrVersion property. If the client machine has .NET installed, this property will return the version number; otherwise it will return 0.0.

     

    Adding a script like:

     

    <script>

     if ((navigator.userAgent.indexOf(".NET CLR")>-1))

     {

          //alert ("CLR available " +navigator.userAgent);

     }

      else

          alert(".NET SDK/Runtime is not available for us from within " +            "your web browser or your web browser is not supported." +            " Please check with http://msdn.microsoft.com/net/ for " +            "appropriate .NET runtime for your machine.");

     

    </script>

    Will help with that.

     References:

     

    ActiveX Documents Definitions:

    http://www.aivosto.com/visdev/vdmbvis58.html

     

     

    Hosting .NET Controls in IE

    http://www.15seconds.com/issue/030610.htm

     

     

Powered by Community Server (Non-Commercial Edition), by Telligent Systems