DCO Secrets 8/21/2001 9: 0: 32 · · QQ New Human ·· Yesky 1 2 Next We have discussed the basic points of DCOM, understand how to create a simple DCOM server and a related customer end. You can also see this basic process is very simple - the ATL wizard process most of the details of the server side, to activate the server, you only need to write about 10 rows in the client. Next we will discuss two related topics. The first is to create your own COM customer and server, combined with the first part we have learned, let you know what to do in your code, do what things you need to do. Then we will quickly look at the code generated by the ATL wizard. The final will explain the steps you need to create a distributed COM server. The so-called distributed COM server means that the server can be in the network, and can be activated very simple and transparent over the network. Create your own COM customer and server in the first part of the DCOM introduction, you can see that you want to create COM customers and servers is very simple. As long as you write a few lines of code in the customer and server, you can generate a complete COM application. You now understand why many developers will use COM when creating a DLL - because only 5 minutes, you can set the COM DLL within a process and work it. The purpose of this section is to discuss how to create your own COM server and use them in the true app you created. You will also remember that the client code introduced by the first part is very small. We will introduce the basic steps to create the server, and then see if you want to activate the server correctly, which code you need to write on the client. The server-side ATL to the COM server creation is very simple. The first step in creating a COM COCLASS is to separate one or more function functions, you have to separate these functional functions from the code body of an application. As for the purpose of separation, it can be diverse, you might want to reuse the function across multiple applications, or it is possible to make a team's programmer more easily separated each independent working group, or let the code Development and maintenance becomes more simple. Whether it is for any reason, the definition function is the first step. One thing that may make these boundaries becomes simpler, which is almost the same as the operation of the COM server and a normal C class. Like a class, you instantiate a COM class, then you can start calling it. The syntax of COM and the syntax and C are a bit different, but their ideas are the same. If a server has only one interface, its actually usage is equivalent to a class. (But when accessing objects, you still need to comply with COM) Once you have defined features and access to it, you can build your own server. In the first part, we already know that you have to create a server, there are 4 basic steps: 1. Use the ATL wizard to create your COM server's housing. You have chosen the server is a DLL, an exe or a service. 2. Create a new COM object in the server's housing. You will choose a thread mode, which will create an interface that can be loaded. 3. Add methods in your object and declare their parameters 4. These steps above the code for your method have been described in detailed in the first part of "Understanding a simple COM server". After the introduction of the first part, a common problem is about thread mode, which is the difference between the COM object's independent thread and the free-threaded. The easiest way to understand the difference between them is to see the standalone thread into a single thread, and the free thread is imagined as multithreaded.
In standalone threads, multiple server clients are called serialized in the COM object of the server-side, that is, after each independent method call is completed, the next method call will begin. Therefore, the COM object of the stand-alone thread is born to be threaded, and the COM object of the free thread can be executed in both the COM object. Method calls for each customer are running in a different thread. Therefore, in a COM object of a free thread, you must pay attention to multithreaded problems, such as synchronization. When you start, you will be more tended to use separate threads because it is simpler, but it is best to turn to the free thread because it has more advantages. 1 2 Next [Published Comments]
【close the window】
■ Related content DCOM secrets six DCOM secret five DCOM secret three DCOM secret two