Help:ATL的进程外程序只能创建一个实例?
ecai 2002-05-27 10:06:31 我写了一个ATL的EXE程序,原来工作正常,可是现在只能创建一个实例了,即在不同的Client程序中调用CoCreateInstance()创建此COM对象时,第一个Client程序会创建一个新的server,但是其它Client程序创建的对象都指向了已经创建的COM对象。
我使用的是2000,在任务管理器的进程中可以看到确实只有一个进程在运行
BTW:CoCreateInstance()的dwClsContext参数
CLSCTX_INPROC_SERVER
The code that creates and manages objects of this class runs in the same process as the caller of the function specifying the class context.
CLSCTX_LOCAL_SERVER
The EXE code that creates and manages objects of this class is loaded in a separate process space (runs on same machine but in a different process).
这两个定义比较清楚,请看下面
#define CLSCTX_SERVER (CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)
#define CLSCTX_ALL (CLSCTX_INPROC_HANDLER | CLSCTX_SERVER)
那么使用CLSCTX_ALL创建COM对象时系统怎么选择让COM对象是作为Inproc Server运行还是作为Local Server运行呢?