场景:com.dll 没有声明其套件类型:
1. CoInitialize(0);
CoInitializeEx(0, COINIT_APARTMENTTHREADED);
只有一个线程:
2. CoInitializeEx(0, COINIT_MULTITHREADED);
进入套件前,只有主线程。
CoInitializeEx(0, COINIT_MULTITHREADED); 调用之后线程没有增加。
CoCreateInstance(CLSID_CBClassFactory, NULL, CLSCTX_INPROC_SERVER, IID_IY, (void**)&piy);
这条语句执行之后,线程数增加。增加了5个。调用失败了。
---------------------------------------------------
客户套件类型 组件套件类型 是否成功 线程数
COINIT_APARTMENTTHREADED 没有声明 调用成功 1
COINIT_MULTITHREADED 没有声明 调用失败 6
COINIT_MULTITHREADED Apartment 调用失败 6
COINIT_MULTITHREADED Free 调用成功 1
COINIT_MULTITHREADED Both 调用成功 1
COINIT_APARTMENTTHREADED Both 调用成功 1
COINIT_APARTMENTTHREADED Free 调用失败 7
COINIT_APARTMENTTHREADED Apartment 调用成功 1
可以看到上面有3中类型的调用失败了,其失败的原因是:
客户套件和组件线程模型不兼容,所以调用失败