Web space - Appendix H COM Integration 1369 Performance Tip H.1
Appendix H COM Integration 1369 Performance Tip H.1 The .NET and COM architectures are fundamentally different in terms of memory management and object representation. Method calls to COM objects can degrade program performance because the RCW must convert all data types between the managed (.NET) context and the unmanaged (COM) context. When we instantiate a COM object in C#, we are actually creating a new instance of the object s RCW. The communication between the RCW and the COM component is entirely transparent, enabling the .NET developer to interact with the COM object as if it were a .NET object. We created an application (Fig. H.6) demonstrating how to use the Simple Addition DLL that we want to integrate into .NET. This program includes three text boxes and a button. After entering an intinto each of the first two text boxes, the user clicks the Calculate button, and the program displays the sum of the two int in the third text box. Line 29 creates the RCW additionObject for COM component Deitel_DLL.CAddition. Lines 55 59 enable the calculateButton button if both text boxes contain values, and disable the button if the text boxes are empty. When the user clicks Calculate, the button fires the event handler calculateButton_Click, which obtains the content of the text boxes and adds the values. The event handler calls COM method addFunction, which returns the sum as an int (lines 74 75). The result then is displayed in txtResultBox (line 77). In this appendix, we demonstrated the use of COM libraries and ActiveX controls from a .NET application. In addition, we briefly explored the history of COM and the differences between its architecture and that of .NET. After reading this appendix, students should have a basic understanding of COM and should be able to use COM components in .NET applications. To learn more about .NET and COM, consult the Web resources described in Section H.4. 1 // Fig. H.6: Addition.cs 2 // Uses a COM component to add two integers. 3 4 using System; 5 using System.Drawing; 6 using System.Collections; 7 using System.ComponentModel; 8 using System.Windows.Forms; 9 using System.Data; 10 using Deitel_DLL; 11 12 namespace Addition 13 { 14 // Adds two integers using a COM component 15 public class Addition : System.Windows.Forms.Form 16 { 17 // display labels 18 private System.Windows.Forms.Label SecondLabel; 19 private System.Windows.Forms.Label FirstLabel; 20 Fig. H.6 COM DLL component in C#. (Part 1 of 3.)
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.