The ATL COM Wizard can create three server types, dynamic link libraries (DLL, Dynamic Link Library, "Exe, Executable, and NT system services (Exe, Service), we know, Win32 system runs in protection mode Next, the memory address of each application is the virtual memory address of the protected virtual memory, and the data communication between the processes is more complicated than data communication within the process, because the block data transfer between the threads or objects within the process can be directly transmitted The pointer, but the data transfer between the processes is required to borrow a more complex process communication mechanism in the system. How does the ATL COM object provide services for other processes within a separate server.
The best way is of course practice, be a sample program.
The difference between the generated code: 1. To the EXE server, the wizard is generated as the same file as the DLL server, but there is no .def file, after all, the EXE server exports to the entry function as the DLL server. The DLL server exports server registration and logout functions via DllRegisterServer and DllunRegisterServer. The EXE server completes the server registration and logout function through parameter / regserver and / unregserver. There are no DllgetClassObject and DllcanunloadNow.
2, DLL server _Module is an instance of ccommodule, and the exe server _Module is a unlocate of CCommodule's derived class CEXEModule, overrides its unlock () method, and it defines two methods MonitorShutDown and StartMonitor. This new derived class monitoring module and exits when appropriate, complete the uninstall of the EXE server.
Same: It turns out that the server adds ATL objects, attributes, and methods, etc., and the DLL server is the same. The system guarantees the cross-trip communication of the ATL COM object.
When the server is an EXE server, the system provides a special object called COM client, called "agent", the agent is an object, which is located in the same address space, and can respond to all interfaces supported by the target component, from The customer's perspective, the agent is the component. When a customer calls a method within a component interface, the agent bundles all the method parameters to a movable data structure collection, and the entire collection is sent to the local server program via remote call, the country is Microsoft RPC Techniques allow programs to communicate across address space, so the agent can easily transfer method parameters into the address space of the local server. In the server side, the RPC is received by a code called the placeholder module. When the method call is completed, the component returns control to the placeholder module (along with all return parameters), the placeholder module will return the parameters to bundle together, package A movable format, then returns them to the agent via RPC, and the agent removes all return values from the return data and retransmit the control back to the customer.
Processes and processes are compared to the advantages of the COM server. Since the process external server is running in a stand-alone process space, the entire system can make the entire system, because the illegal operation of a process does not affect the other process, especially when the COM server is not stable. The server is running in the same process space as the customer, avoiding the call overhead of the RPC, making the calling process more efficient. faster.
The ATL Wizard supports the COM server to provide four thread model options, SINGLE, APARTMENT, BOTH, FREE, is used to support single-wire models, unit thread models, and free thread models. Let's learn next time.
Still too nick, diligent practice COM.