你这么说我越发哆嗦了. 从前做过一个项目有类似的问题, 附上当时的技术纪录, 只供参考, 再多咱也不会了. 另外static可以用.

guest (哆嗦)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
DCOM Threading Models, Server, Client, and Object Instances:
After a few reading and testing, this is clear.

For the server:

Single threaded model will only create one thread for DCOM object,
More than one instances can be created from one object (class). Then
each object is a different internal pointer, and is associated with
one client and one possible callback connnection point. There is only
one hidden window serving as message pump for DCOM:
(OleMainThreadWndName (with class OleMainThreadWndClass))
All the incoming calls to the server are linedup and thread safe, no
matter the client is free-model or not.

If Singelton class factory is used, only one instance of the object
is created, all clients share the same server instance.

The callback should be in the same thread, otherwise thread marshaling
may be needed to create a new pointer for the callback. Create another
hidden window in the main thread will garantee

Multithreaded run time library can be linked for the server if the server
involves different threads even for single threaded server. Only the service
is single threaded, internally there can be several working threads to
support the service.

Apartment threaded model can generate thread pool if inheritted from
CComAutoThreadModule rather than CComModule. Inside each thread, there
is a call pair to CoInitialize and CoUninitialize to create an
apartment for the thread. Still there is only one hidden window for
message pump, and all calls are lined-up no matter the thread model of
the client. But each object instance is associated with a thread.

Free threaded model will generate a thread for each instance, but
there is no message pump window, all access should be thread safe
designed by the programmer.

For the client:

Advantage of using free-threaded client, no need to call CoInitialize
and CoUninitialize in each thread and marshaling the object pointer for
each thread. All calls can be in the same main free-thread apartment, which
is created in the main thread by CoInitializeEx. Plus if the server supports
free-threaded model, it will be all multi-threaded access for all the calls.
If the server is single threaded apartment, it does not hurt anything,
the server will line up all incoming calls. So in this case, the DCOM will
block the program flow even the client is multi-threaded.

Apartment threaded client, each apartment is within a thread, and is created
by calling CoInitialize and destroyed with CoUninitialize call. This will
generate a message pump, and add the apartment into the existing message pump.
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#66357@0)
2001-5-10 -05:00

回到话题: 初学COM,请高手指教,也欢迎初学者讨论。题目是:“如何在多个COM OBJECT之间共享数据?”

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=66357