1

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

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

i have done CoInitialize(NULL); but now i am getting another exception "_com_error at memlory location 0x2321123..",
@fhnaseer you get this on the call to CreateInstance?
i debugged it, now i came to know that the error is "The application called an interface that was marshalled for a different thread", i think this is due to some complexity in my code,
@fhnaseer that seems to be a different issue.
2

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

1 Comment

i have done CoInitialize(NULL); but now i am getting another exception "_com_error at memlory location 0x2321123..",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.