COM AND COMPONENT CREATION IN C#

 

COMPONENT:

Component is nothing but the reusable pieceof software in binary form that can be plugged into other componentsfrom other vendors. Reusable software programs that share a commoninterface allowing easy integration into applications that is it is aBinary standard that allows any two components to communicate thatcomponent may be written in any language.

NEED FOR COMPONENT:

Today?s applications are time consuming todevelop, difficult and costly to maintain and we cannot remove afeature, upgraded or replaced with alternatives. The solution for thisproblem is reusable software components. Each function has a distinctfunctionality. Microsoft word Word Processing software. Microsoft ExcelSpread sheet-analyze &manipulates data.This is a situation where we find ourselves requiring features that arenot a part of the application we are using.

SOLUTION:

The solution to this problem is to isolatethe functionality that is required by many applications and creates anew application from it and makes into a common functionality. Eachtime the client requires the functionality then it should be called anduses its features as though they were its own.In our project we create the Components from the five applications sothat the users can easily use it in many languages and upgrade iteasily.

COM FRAME WORK

To create application that can interact withany other application requires that there be a standard manner in whichthe two applications will interact. So, for that we need a frameworkthat defines the rules that will enable to interact with each otherirrespective of who has created the application.

COM AS BLUE PRINT:

If all the application follows the same rulesfor interaction then application created by different people caninteract with each other and we can exploit any application to obtainthe feature we need.Microsoft has defined a model that sets standard that will enableapplication to interact with each other. This model is referred to asthe COM. It defines the rules which when implemented will enableapplications to interact with other application in a uniform manner.Both calling application and the called application need to follow therules specified by the COM.Calling application search the hard disk will be a time consumingaffair. Thus COM states all applications that can be provide servicesto each other application must be registered at a central location. ButCOM doesn?t define what this location is to be or the information thatis to be registered.Thus COM acts as blue print.So Com just defines thetheory but not how they are to be implemented.

MICROSOFT?S COMPONENT OBJECT MODEL (COM)

When we register a COM or DCOM object withinthe window registry, we must reference that object?s Globally UniqueIdentifier (GUID), which is a 128-bit (16-byte) number that uniquelyidentifies the object. Whenever a client program accesses a COM or DCOMobject, the client program will use the GUID to reference the objectwithin the windows Registry.Another powerful COM feature is language independence. COM clients andCOM objects have the same layout and behavior at run time, regardlessof which language we use to produce the component. COM?s independencefrom any specific language lets build systems with many differentcomponents that other programmers create in different language, whetherVisual Basic,C++, or Java. The language we use to create the component simply doesnot matter in COM.First, it helps in split up large systems into manageable subsystemsearly in the design phase.Second, it assists to implement each subsystem with a component that wecreate with any Com-capable tool.Third, it lets individual teams working on each subsystem has complete.The two most notable of these technologies are OLE (Object Linking andEmbedding) and ActiveX. These both use COM to facilitate all theinteraction between objects. OLE uses COM to communicate betweenapplications, allowing users to link or embed parts of oneapplication's data and display into another application.

INTERFACES OF A COMPONENT:

MICROSOFT?S INTERFACE DEFINITION LANGUAGE (IDL)

The fundamental concept behind both COM andDCOM is the interface. An interface is an agreement between a clientand an object about how they will communicate with each other. When wedefine interfaces in languages other than the visual basic, we have touse Microsoft?s Interface Definition Language (IDL), which we mustcompile within the Microsoft Interface Definition Language Compiler(MIDL).

GLOBALLY UNIQUE IDENTIFIER (GUID)

Each interface that we define in a COM objectwill include a Universally Unique Identifier (UUID), which theoperating system constructs exactly as it does a Globally UniqueIdentifier. When client programs access an interface the COM objectexposes, the programs will actually reference the interface?s UUID. Aninterface is an agreement between a client and an object about how theycommunicate. The interface becomes a communication channel between theclient and the object. Within our program code, an interface is acollection of related procedures and functions.

FUNCTIONS OF INTERFACES

When we create objects that we build aroundCOM and clients to communicate with the COM objects, both the clientsand the objects must communicate exclusively through interfaces.An interface between two objects is actual program code. A logicalinterface is the model for the program code itself. An interface playsthe mediator?s role between the client and the object and is a contractthat specifies the work the object must do, but it dose nit specify howthe object should accomplish the work. In addition, an interface is acommunications protocol that defines a set of methods complete withnames, arguments and return type.A COM object must implement at lestone interface, although the object is free to implement as manyinterfaces as it requires.The object creates an array of functionpointers, called a V table (the ?V? stands for Virtual), and passes a VTable pointer to the client. The client sees the V Table as theinterface and uses the V Table pointer it received from the client tolocate a particular function pointer.when the client finds the functionpointer, the client invokes the method directly. In other words, whenprograms access the COM object, they will always access the V Table andreceive a vptr from the V Table?s. When we compile the COM-basedproject, the compiler feeds the Interface Definition Language file tothe Microsoft Interface Definition Language (MIDL) compiler, produces abinary description file called a type library.Unlike C++ and Java, Visual Basic does not require using InterfaceDefinition Language or the MIDL compiler. The Visual Basic InteractiveDevelopment environment (IDE) creates a type library directly from ourVisual Basic source code and builds the type library information. If wewant to see the Interface Definition Language for a particular COMcomponent, we can use the ole view, utility to ?reverse engineer? atype library into Interface Definition Language text. The type librarylets development tools, such as the Visual Basic compiler and theVisual J++ compiler, build the Table binding at compile time.

<

b>COMPON
ENT CREATION IN C#

INTEROPERABILITY
1. C# includes native support for the COM and windows based applications.
2. Allowing restriced use of native pointers.
3. Users no longer have to explicityly implement the unknown and other COM interfacers, those features are built in.
4. C# allows the users to use pointers as unsafe code blocks to manipulate your old code.
5. Components from VB NET and other managed code languages and directlyt be used in C#.

COMPILING THE COMPONENT

The creation of the component is a simplywriting a class program with in a normal application but in compilationwe have to create a library instead of an application.After creating a seprate library file that can be used in a clientapplication.

The compilation process should be as follows
csc /r: REFRENCE DLL /t library /out DLLNAME.DLL Program name.cs

The "/t library" in compilation code says theC# compiler to create a library and also tells to not to look for a'static Main() method. In "/r" we have to add the required namespaceDLL.After the compilation we have the required library which is readyto use in the client application.To use a component in clientapplication we have to compile like this

csc \r:components library DLL name program name.cs

ex: csc /r: arun.dll component.cs

The code is simpler, and there are only twofiles (client and server) to deal with. For a sufficiently largeapplication the amount of C code is going to be comparable to theamount of C# code.

CONCLUSION

According to Microsoft's marketing, componentdevelopment is vastly simplified in .Net framework. Creating andmanaging dll files is takes a lot of windows developer resources. Themain advantage of C# comes from the reduced number of files and theabsence of complex linker options and header files.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!