fhnaseer
fhnaseer

Reputation: 7277

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?,

Upvotes: 1

Views: 328

Answers (2)

Nemanja Trifunovic
Nemanja Trifunovic

Reputation: 24559

You need to call CoInitializeEx in each thread that uses COM.

Upvotes: 2

Luchian Grigore
Luchian Grigore

Reputation: 258698

You need to call CoInitialize() in every thread before attempting to create instances.

Upvotes: 2

Related Questions