COM 스레드 모델 - MTA 인터페이스(MTA COM 객체가 STA 스위칭 스레드에 전달됨)

2272 단어
이어서 한 MTA 스위트룸에 만들어진 COM 대상을 STA 스위트룸으로 전달할 수 있을까요?MSDN의 설명을 보려면 다음과 같이 하십시오.
A client or server that supports both single-threaded and multithreaded apartments will have one multithreaded apartment, containing all threads initialized as free-threaded, and one or more single-threaded apartments. Interface pointers must be marshaled between apartments but can be used without marshaling within an apartment. Calls to objects in a single-threaded apartment will be synchronized by COM. Calls to objects in the multithreaded apartment will not be synchronized by COM.
위의 이 문장은 이미 매우 분명하게 말했다.우리는 하나의COM 대상을 다른 칸막이로 직접 전달할 수 없다.다시 말하면 크로스 룸과 관련된 일이라면 반드시 마스홀이 필요하다.
그래서 앞의 글의 예에서 보조 라인이 STA로 초기화되면 COM 대상 지침을 직접 전달할 수 없기 때문에marshal이 필요하다.그러나 보조 라인도 MTA라면 상관없다. 보조 라인과 주 라인이 모두 MTA 안에 있기 때문에 같은 세트에 마스홀이 필요하지 않다.
그렇다면 보조 라인이 어느 칸에 속하지 않고 일반 라인에 속한다면?
나는 이 자료들을 찾았다.http://support.microsoft.com/kb/150777
NOTE: Current implementations of COM allow a thread that does not explicitly initialize COM to be a part of the MTA. A thread that does not initialize COM is part of the MTA only if it starts using COM after at least one other thread in the process has previously called CoInitializeEx(NULL, COINIT_MULTITHREADED). (It is even possible that COM itself may have initialized the MTA when no client thread has explicitly done so; for example, a thread associated with an STA calls CoGetClassObject/CoCreateInstance[Ex] on a CLSID that is marked "ThreadingModel=Free" and COM implicitly creates an MTA into which the class object is loaded.) See the information on threading model interoperability below.

대략적인 의미는 다음과 같다.
현재의COM 디자인은 COM을 초기화하지 않은 라인을 MTA 세트의 일부분으로 허용한다.다른 라인이CoInitializeEx(NULL,COINIT MULTITHREADED)를 호출한 후에만 COM을 초기화하지 않은 라인이COM을 MTA 세트에 사용하기 시작합니다.(한 가지 가능성은 COM이 자체적으로 MTA로 초기화되지만 고객이 현저하게 초기화되지 않았다는 것이다. 예를 들어 STA 라인이'Threading Model=Free'라고 표시된 CLSID에서 CoGetClsObject/CoCreate Instance[x]를 호출하면 COM은 은밀하게 MTA 스위트룸을 만들 것이다)
ok, 우리의 경우 보조 라인은 자신이COM을 초기화하지 않았음에도 불구하고 MTA 세트의 한 라인이다.그래서 마스홀도 필요 없어요.
또한 마스홀과 unmarshal에 관해서는 기본적으로 두 가지 함수에 의존한다.
CoMarshalInterThreadInterfaceInStream andCoGetInterfaceAndReleaseStream
앞의 문장 안에 예가 있다.(STA 스위트룸에서)


좋은 웹페이지 즐겨찾기