简体   繁体   中英

Creating COM object in Threads

I have a button, behind that button i created a thread,

void FunctionCallingThreadFunction()
{
    AfxBeginThread(MyFunction, NULL);
}

In MyFunction i am creating a COM object, but when I create instance of it, null is returned to me,

MyFunction(LPVOID pvParam)
{
    comObject.CreateInstance(__uuidof(ClassName), NULL, CLSCTX_INPROC_SERVER);
}

But if i create this comObject in origional function it is created fine,

what is problem?,

在尝试创建实例之前,您需要在每个线程中调用CoInitialize()

您需要在使用COM的每个线程中调用CoInitializeEx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM