COM Threading Model 01

Source: Internet
Author: User
Tags ole stub wrapper knowledge base

Coinitialize;

IUnknown;

Apartment

"Insider of COM Technology", "com Essence", "Insider of COM Technology", "in-depth understanding of COM +"

-------------------------------------------

Essay Classification-j.com Technology:

Http://www.cnblogs.com/Clingingboy/category/198480.html

Information about the COM suite:

Currently found only this one complete, but the people are ridiculous is the curse of the majority of the people discussed but few

http://www.vckbase.com/document/viewdoc/?id=1597

The following discussion of this post is also very exciting

Http://topic.csdn.net/t/20021117/21/1184068.html

About COM and Suite (Apartment) knowledge

http://blog.csdn.net/wojiaopanpan/article/details/7574961

My view of COM and suite:

Http://www.fx114.net/qa-211-55637.aspx

please explain the meaning of apartment (suite) in com:

http://bbs.csdn.net/topics/20121276

VC Knowledge Base:

http://www.vckbase.com/index.php

==================================

Proxy stub just like you and your girlfriend on the phone, you hold the microphone and say, she is listening with the microphone, what does not matter!
You take the equivalent of the microphone agent, she took the equivalent of stubs, the middle of the implementation process you do not care, the main transmission is the voice of each other's good!
Suites are equivalent to adding a shell to COM components
We use the House to represent the suite, the people represent the COM components, each house has a computer

Single-Thread Suite (STA)
This House can only hold one person A, this person uses a computer, can be used directly (between the threads in the same
memory address, so do not use the proxy), should be for him in a house. And the outside of this House
Man B (Agent), want to use his computer, must come knocking, but because of the use of many people
In order to queue up (the role of the hidden window first-out principle) wait until his turn,
A Open the door (stub) let B in, a went out, because I suppose the House can only accommodate one person.
This avoids the problem of synchronous inter-race running between threads.
Multi-threaded Suite (MTA)
is quite this house is relatively large, there is a computer in the house, but can accommodate a lot of people, A, b
C,d,e in another house, C to use the computer of that house must be the same as Sta.
Through the stub agent!
But the MTA problem comes out, a, a, if rob a computer to use, how to do?
This is what programmers need for programming control!
Leased thread Suite (RTA)
The house is empty, and the computer is idle.
Someone wants to go in and go straight in, without using stubs and proxies.
But someone went in and someone wanted to play the computer. I'm going to wait outside the door, the old gentleman.
Play cool, play enough, come out, can go in. This is by using proxies and stubs,
But this is just a concept, Microsoft just mention it!! You don't have to worry about it here!

-----------

Your metaphor is pretty good, but there may be some problems. As you said, the House represents the suite, and the person represents the COM Component object. "The single-threaded suite (STA) is the only one in this House. A", should that be what you mean? However, the STA should be able to have multiple COM objects at the same time. I think it should be more appropriate to compare "computer" to COM object and "person" to a thread. Like what:
Single-threaded Suite (STA): This House (STA) can only accommodate one person (suite thread), and may have multiple computers (COM objects). Of course, this person will only use one computer at a time. People outside the house (other suite threads or free threads) who want to access the computer (COM object) in this House, must make some call rules (Message Queuing) through the people in this House (the suite threads in the STA)!

--------------------------------

First, let's examine the question: if we create a COM object, where is its entity? Simply put, in the suite (apartment), then where is the suite? I think the latter question is exactly what we are puzzled about. So let's take a look at one of the facts under Windows: If our program calls a DLL, where is the DLL? If more than one program calls a DLL, where is this dll? The answer is that the first DLL in the start of his program address space, and then started the DLL does not really load, still use the original DLL, as to how the different processes (this is usually the maximum boundary of the program) to coordinate these things, then Windows things, we do not need to tube him. In fact, the DLL is already in such a position: on the one hand it is subordinate to a certain application, while it can be free to cross the process (of course there are limitations, and only the system can do), this duality, and the process is very different, we can even imagine it living in a separate space, Who will serve who it is-and that is the best way for COM to survive. As an analogy, it is not difficult for us to understand the concept of a suite, which is a system-constrained "stand-alone space," a place where COM objects are "Born and killed", and where applications need COM objects. The size of the suite can be large and small, the location is also very casual, size can be from the DLL to the application, or even the overall system, the location can be in the DLL (that is, in the process), can be beyond the process, or even across the system and the network (DCOM is so). Suite because of the system to get the right to almost free, then obviously the application can not be arbitrary access to their own will (bad operation of the most crashes, malicious operation may be another CIH ^_^). How to access the suite is another problem we need to solve. (This on the suite actually made a simplified concept of the discussion, I think for the understanding should be just right, the specific norms you refer to the "com Essence" bar)

The way to access the suite is the interface in COM, that is, we can only let the user access to the COM object's service functionality, but not to allow users to access their private data (which is often the key to system stability and security issues). COM's binary sense interface has provided us with good conditions, which can be accessed from one interface point to all, but also from one pass to another, itself (that is, conform to reflexive, transitive, symmetric, form a closure). Since an interface is the equivalent of prying up the Earth, the remaining question is, what kind of power do we need to acquire this first interface? Who has such a great power? I think this time, we all already know, is the Windows system. The system gives us the ability to do this, but there is a limit: either when you create a COM object, you give us the first interface to our object through a IUnknown interface (that is, the last parameter in the CoCreateInstance function, pay attention to Oh ^_^) And the other way is our containment. After advise registers itself with an OLE object, the OLE object passes its own IUnknown interface through parameters through the SetSite function (yehh,bingo! )。 Besides, I think that unless you have a close relationship with Bill's brother, perhaps windows will consider spared's ^_^.

With Aladdin's lamp "IUnknown", we can query the various interfaces it supports based on the type of COM object. For example, we can get the IID of the interface according to the document (for example, Mshtml, which has good documentation support), and then query to get more interfaces , or (for example, Word, etc.) we can invoke all functions completely through its IDispatch interface (DispID can be obtained from the implementation of the wrapper class by adding wrapper classes in the MFC project). Now, is there some "give me an interface, I can drive the Earth" feeling of ^_^

COM Threading Model 01

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.