Chapter 2: Migrating Unmanaged Applications


You migrate unmanaged applications, such as Component Object Model (COM), Distributed COM (DCOM), Active Server Pages (ASP), and Win32 applications, to .NET to provide flexibility, a faster execution time, and improved security. Using .NET, you can also create Web applications for use on various devices, such as mobile phones, laptops, and computers. In addition, by using unmanaged code with managed code, you can make the unmanaged applications interoperable.

This chapter describes various types of unmanaged applications and the advantages and disadvantages of migrating unmanaged applications to .NET. In addition, it explains the different types of migration and the interoperability framework.

Unmanaged Applications

Code of unmanaged applications compiles directly to binary code. Various types of unmanaged applications include COM, DCOM, and Win32 applications.

Types of Unmanaged Applications

Unmanaged applications are 32-bit applications, which are categorized into:

  • COM applications: Allow you to reuse different components in an application. Reusable components can interoperate with other components written in the same binary standard. COM objects provide interfaces to allow applications and components to access their features. You can use any language that adheres to COM specifications, such as Visual Basic (VB) 6.0 and Visual C++, to create and use COM components.

  • DCOM applications: Allow software components to interact directly over a network in a consistent, secure, and efficient way. DCOM works with ActiveX components and Java applets. DCOM allows you to distribute an application at different locations. To access a method of a remote component, DCOM uses a proxy object, which generates a Remote Procedure Call (RPC) to the remote component.

  • Win32 applications: Use the Win32 Application Programming Interface (API) to create Win32 applications, which run on the Windows 95 and later platforms. Win32 APIs abstract the complexity of code of Win32 API functions and provide the required functionality to end users. The Win32 API, a successor of the Win16 API, is a library of data types, definitions, and functions to create applications that run only on the Microsoft Windows operating system. You use 32-bit registers to process Win32 applications, which can be written in different languages, such as Pascal, Java, C, and C++.

  • ASP applications: Use the ASP server-side technology to create dynamic Web pages that respond to end user actions on the Web pages. ASP runs on Internet Information Services (IIS) or Personal Web Server (PWS). IIS runs on Windows NT 4.0 or later and PWS runs on Windows 95 or later. You can write ASP code in a simple Notepad file and save the file with the .asp extension. The ASP script runs when the Web server receives a request for a page from a Web browser, such as Internet Explorer.

Advantages of Migrating Unmanaged Applications to .NET

Microsoft .NET is a flexible, reliable, and secure platform for application development. Migrating applications to .NET enables you to create applications using multiple languages, execute the applications on disparate platforms, and improve the efficiency of the applications. The advantages of migrating unmanaged applications to .NET Framework are:

  • Security: Provides better support than unmanaged applications to secure applications from unauthorized access. Unmanaged applications use Access Control Lists (ACLs) and security identities but do not provide a security check to restrict access to specific sections of executable code. .NET provides security to the executable assembly and Code Access Security (CAS) to particular sections of executable code. For example, in a .NET application, you can restrict a portion of code from accessing a resource by using permissions, permission sets, and CAS. You can also assign different levels of permission sets to different end users and assemblies. The Common Language Runtime (CLR) provides security check on .NET applications at run time. As a result, you need not explicitly code to detect security failures in the application.

  • Versioning: Enables you to work with multiple versions of the same assembly simultaneously. Each assembly in .NET Framework contains a four-part version number as part of its identity. This version number distinguishes between different versions of an assembly for simultaneous execution. In simultaneous execution, different versions of an assembly can be installed on the same computer. In unmanaged applications, you cannot maintain versions of an application. If you install a new version on the same computer, Dynamic Link Library (DLL) files overwrite the older versions, which might stop the older versions from running.

  • Performance: Enables you to create applications that run faster than unmanaged applications. When you execute your .NET application for the first time, the .NET runtime compiles application code to Intermediate Language (IL) code and then converts the IL code to native code. When you execute the application again, the .NET compiler does not recompile the existing IL code to native code, which enhances performance. Applications written for the Web also perform better due to the caching feature in ASP.NET. In addition, ActiveX Data Objects (ADO).NET provides platform-independent, disconnected access to requested data, which improves the performance of managed applications.

Note

To learn more about caching in ASP.NET, see the ASP.NET Caching ReferencePoint.

  • Reliability: Provides type safety to .NET applications. The CLR identifies and confirms types before you can load and execute them, which reduces the possibility of elementary programming errors and prevents buffer overruns that can cause security problems. For example, a method in the .NET application accepts an Int32 variable as a parameter. If you pass an Int64 variable in the method call and compile your application, you receive a compilation error because the Int32 type differs from the Int64 type. Unmanaged applications do not provide any mechanism to check type safety. You can write programs where you pass parameters of different types, and you can still execute the program. For example, a method in the application accepts a string variable as a parameter. If you pass an integer variable in the method call and execute your application, you do not receive an error.

  • Consistent programming environment: Provides a consistent, object-oriented programming environment that allows you to use various languages, such as VB.NET, C#, J#, or C++ managed extensions in .NET applications. For example, you can create a class using VB.NET and extend the class using C#. You can implement inheritance, polymorphism, and catch exceptions in different languages. Unmanaged applications do not provide a consistent programming environment. You need to know different programming environments for diverse languages, such as Visual Basic, C++, and Visual J++.

  • Automatic resource management: Mitigates the process of writing explicit code to manage resources, such as files, memory, network connections, and database resources. When you write an unmanaged application and do not free the allocated resources, the application may not execute properly. .NET Framework provides garbage collection, which automatically manages resources.

  • Ease of deployment: Simplifies the task of application deployment. You only need to copy the appropriate files to the destination computer. The assemblies in a .NET application are the basic units of deployment and store all the information about how the .NET application implements classes, structures, and interfaces. As a result, it is not required that the registry entries should store information about the application. In addition, assemblies also contain information about the versions of the components used by an application. This simplifies the process of versioning components. Unmanaged applications cause deployment problems. VB 6.0, VC++, and ASP applications use registries to deploy an application. For example, if a Windows application uses few shared DLLs, and you install software that overwrites one of the shared DLLs, the application stops running and you may need to re-install the application.

  • Improved developer productivity: Provides a number of base class libraries that include many classes and their methods, which you can reuse. This reduces the time and cost to develop the code. The .NET runtime manages background tasks, such as memory management. This helps you concentrate on developing the application without worrying about managing resources. Unmanaged applications do not provide such facilities.

  • Backward compatibility: Allows you to reuse existing applications, such as COM applications. .NET builds a wrapper around existing applications, which allows the .NET applications to interoperate with COM applications.

  • Portability: Allows you to reuse components and classes with any .NET-compliant development language, such as VB.NET, C#, and C++ with managed extensions. Unmanaged applications do not provide the feature of component reusability and cross-platform classes.

  • Remoting: Allows you to write applications that access components that may not exist on the same computer, server, or application domain. You can use remoting to assemble components and method calls across processes and transmit data between applications. Before .NET, you could transmit objects across processes using DCOM. The type of data transmission or the security environment transmitted between the client and the server limited the scope of the earlier technologies. In addition, all machines needed to run on a Microsoft operating system.

  • Component infrastructure: Provides ready classes that you can use at the binary level. The extra code to support components in .NET Framework is not required. You only need to write a .NET class, which becomes a part of an assembly that provides support to plug-and-play devices. .NET eliminates the use of registries for component registration and the writing of code to support IUnknown, class factories, dynamic binding, component lifetime, and registration. Unmanaged applications use integrated binary components in their applications. You need to follow the COM identity, lifetime, and binary layout rules. You also need to write code to create a COM component, such as CoRegisterClassObject, which registers an EXE class object with Object Linking and Embedding (OLE) to allow different applications to connect to the component.

  • Web service support: Provides Web services and creates files, such as Web Services Description Language (WSDL) files, for the Web service, which expose different functionalities to end users through standard protocols, such as Simple Object Access Protocol (SOAP). You can communicate across disparate platforms and firewalls. In unmanaged applications, DCOM performs similar tasks but with limitations, such as it cannot communicate across disparate platforms or firewalls.

  • Standard toolset for any .NET language: Enables you to create applications in any language that is compatible with .NET. For example, you can use the same set of controls for Windows application development whether you code the application in VB.NET or C#. You need not worry about learning dissimilar tools for different languages. Unmanaged applications necessitate the use of Windows APIs, Microsoft Foundation Classes (MFC), COM interfaces, Active Template Library (ATL), scripting languages, and several other environments that are difficult to understand and implement.

  • Support for mobile devices: Enables you to create applications that run on various mobile devices using Microsoft Mobile Internet Toolkit (MMIT). Unmanaged applications do not provide intrinsic support for mobile devices.




Migrating Unmanaged Applications to. NET
Migrating Unmanaged Applications to. NET
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net