Reputation: 7277
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?,
Upvotes: 1
Views: 328
Reputation: 24559
You need to call CoInitializeEx in each thread that uses COM.
Upvotes: 2
Reputation: 258698
You need to call CoInitialize()
in every thread before attempting to create instances.
Upvotes: 2