[ Pobierz całość w formacie PDF ]
.Managed classes returned from method calls do notnecessarily have to be registered as COM components.The CCW will convert amanaged class to a suitable COM component for the COM client.Activation LifecycleLet s firm up these concepts by walking through each phase that must occur whena COM client loads a class and begins to call methods.Before a COM client caneven get an instance of a managed class, it must find the COM dll, load it, and getaccess to its class factory.The process for doing this is as follows:1.Query the Windows Registry for the CLSID, given a specific ProgID.(Remember for.NET classes the ProgId is the namespace.classname.)2.Given the CLSID, the client queries the registry for the CLSID Key.Thesection Registering Assemblies with COM shows what this key looks likefor a.NET class.3.The client calls the COM API DllGetClassObject, passing in the CLSID,to get a reference to the class s ClassFactory.Step 3 is where things start to get interesting.MSCorEE.dll is the COM server forall.NET classes including COM+ classes.When a COM client requests a class fac-tory, MSCorEE.dll queries the.NET Class Loader to see if that class has been loaded.If the class has been loaded, a class factory is returned to the client.The CCW isresponsible for creating this class factory and returning it to the client.However, ifthe class is not loaded, the CCW looks at the assembly key in the registry to deter-mine the name, version, and locale of the assembly.This information is passed off tothe.NET assembly resolver.At this point, the assembly is located through the normalassembly location algorithm.All of the versioning rules, config-file overrides, andlocation rules we discussed in Chapter 1 are applied at this point.Remember, unless054835-2 Ch03.F 8/31/01 8:09 AM Page 4242 Part I: Interoperating with COMClass FactoriesClass factories are special kinds of COM classes responsible for creating instances ofother COM classes.For the most part, each class or object in COM has a correspondingclass factory responsible for creating instances of itself.A class factory is responsiblefor creating only one instance of the class it represents.Using class factories tocontrol the creation process of classes has several advantages over simply making acall to the COM API, CoCreateInstance:The author of the COM class can use his or her knowledge of the class toimprove efficiency of the class factory and thus improve the creation process.The class-factory model provides a level of indirection that can be used tocatch errors during the creation process.The class factory simplifies the creation of classes for COM s clients.Class factories also provide an efficient way to produce multiple instances of a class.In a multi-user environment, such as a Web server using COM+ components, classfactories are used to create instances of COM+ objects as user requests are received.In fact, COM+ caches instances of class factories to improve the object-creation timesof COM+ objects.the assembly is in the same directory, in a subdirectory, or in the Global AssemblyCache, the assembly resolver is not able to find the assembly.Once found, the assembly is passed back to the Class Loader.The Class Loader isresponsible for loading the assembly and determining if the assembly implementsthe class (by reading its metadata).Assuming the class is found within the assem-bly, the CCW creates a class factory and returns it to the calling client.The class factory returned to the client is a standard COM class factory on whichthe client can call IClassFactory.CreateInstance() to get an instance of theCCW that wraps the underlying.NET class.IClassFactory.CreateInstance()takes three parameters:a pointer to IUnknownan interface ID (GUID defined in the type library)a void pointer used to hold the reference to the objectWhen the client passes in the IUnknown pointer, the CCW compares the valuesof the pointer to the instance of the class for which the class factory has beenreturned.By doing this, the CCW preserves the identity of the.NET class.When CreateInstance() is called, the CCW returns the interface to the clientand sets up the VTable for the interface s methods.Figure 3-1 shows a VTable foran interface called IList that defines methods for MoveFirst, MoveLast, and Goto.054835-2 Ch03.F 8/31/01 8:09 AM Page 43Chapter 3: Consuming.Net Components from COM 43COM clientVTable for Interface IList COM Callable Wrapper.Net Runtimepublic class CTable : IListpointer for stub forIList.MoveFirst()MoveFirst() MoveFirst()pointer for stub forIList.MoveLast()MoveLast() MoveLast()pointer for stub forIList.Goto(int i)Goto(int i) Goto(int i)Figure 3-1: VTable for Interface IListWhen the client calls MoveFirst and MoveLast, the CCW manages the transitionbetween managed and unmanaged code and catches any exceptions the methodsthrow
[ Pobierz całość w formacie PDF ]
Linki
- Indeks
- informatyka programowanie wspolbiezne systemy czasu rzeczywistego pawel majdzik ebook
- Addison Wesley LDAP Programming with Java (2000)
- java programming unleashed [ EN ], Java2
- instrukcja instalacji do programu relux
- Christopher Anvil Prescription for Chaos (com v4
- Com Tajemnica internetu Rifle Alex
- Egejska Ewa Czarodziejki.com
- Iles Greg Anioł z Missisipi
- Lechon Jan Dziennik t.2
- prawo ca%b3o%9c%e6
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- natiwa.pev.pl