Visual Basic is a third-generation event-driven programming language belonging to Microsoft. It is based on the Component Object Model (COM) programming model and designed for beginners. The Last Version is the 6 (1998) and the core of FirmaDoc, our Spanish product dedicated to document and file management for public administration is written in VB6. However, Microsoft announced in 2008 that they will stop supporting Visual Basic 6.0 IDE. The Microsoft Visual Basic team still maintains compatibility for Visual Basic 6.0 applications on Windows through its “It Just Works” program. All versions of the Visual Basic development environment from 1.0 to 6.0 were retired by Microsoft by 2008 and are therefore no longer supported. The associated runtime environments are also unsupported, except for the Visual Basic 6 core runtime environment, which Microsoft officially supports for the lifetime of Windows 8 and Windows 10.
Since 2008, Microsoft stopped supporting Visual Basic 6.0 IDE.
Besides the fact that no one can be sure that the next version of Windows will continue to support VB6 Core, this language is criticized for its poor memory management performance and for the possibility that it offers to be able to build code using not very academic constructions, being able to give bad programming habits and allowing to write poor performance code. To make things worse, there are big chances that more than 20 years of solution development represents a lot of difficulties to maintain it stable and deployable. Something needed to be done right now.
Java Native Access (JNA): The Matchmaker
Visual Basic offers the possibility to create some COM Components like ActiveX Exe or ActiveX DLL. Nowadays, the most common model of a distributed application is the client/server application model. All VB6 application dependencies are resolved using a “main” program which defines a virtual memory space that can host linked objects needed (like a DLL object).
A COM object allows the client to instantiate it in its memory space when interrogating its interface. In fact, at compile-time, VB6 creates an interface for each DLL class and each interface inherits from IDispatch which inherits itself from IUnknown; both are standard COM rules for implementing COM objects, regarding the Microsoft COM Programming Model. The compiler generates a Type Library File (.tlb) which describes the structure of a COM Component including Imports, Fields, and Functions.
This file is then used by a Java Class Generator to implement and use COM Object in Java Application using JNA as a native Interface framework. The JNA library is used to dynamically invoke native code. It uses native functions allowing the code to load a library by its name and to retrieve a pointer to a function of the library. No need for static links, header files, or compilation phase. The developer uses a Java interface to describe the functions and structures related to the target native library. JNA is an overlay of JNI allowing to avoid the tedious configuration and construction of JNI code.
JNA is built and tested on macOS, Microsoft Windows, FreeBSD / OpenBSD, Solaris, GNU with Linux, AIX, Windows Mobile, and Android. It is also possible to modify and to recompile native build configurations to make it work on most other platforms that run Java. With Java and Java Native Access, we can replace the “Main” of a VB program (Context) by a Java Application that uses the COM Object (Dll) as a Business Logic code. The purposed Model is a third Party Architecture allowing to separate each component of the Application:
Conclusion
Overall, we have demonstrated in practice how legacy VB6 code can be encapsulated within a Java-based application, thus allowing us to keep running the core of FirmaDoc. Despite the technical prowess, the resulting architecture has some very interesting benefits such as allowing users interfaces to be modernized and to separate clearly Client and Server code. In addition, VB6 offers poor possibilities to manage multi-threading applications, at the opposite Java SpringBoot Rest is known as a better solution. The Logic code does not need to be modified, and Dlls can be used with high performance (Binary Code and Runtime) to enable the best User Experience and to removing all communications (web service, socket, tcp/ip) between the VB application and other applications. The code maintenance is made easier by the better organization of the application’s components.
In a context of migration, this solution also allows a step by step code transfer/rewriting (Class by Class) and the development of new features can be done in Java for the Rest API and using a new framework such as Angular, Spring boot, Spring Cloud, Microservices, etc. such an approach would allow stopping the technical debt.