QueryInterface fails 
Author Message
 QueryInterface fails

I have a very strange problem with a COM object.

The COM Object class name is CMyComObject and it supports
the two interfaces IMyComObject and IMutableMyComObject.

When the system has been running for a couple of days
successfully in release build (it never happens in debug
build) this function starts to fail:
pMyComObject->QueryInterface(IID_IMutableMyComObject,
reinterpret_cast<void**>(&pMutableMyComObject));

The pMyComObject pointer is created successfully on the
line before this. So we know that it is successfully
created and we know that it supports the interface. Still
the QueryInterface fails. And once it has started to fail,
it will continue to fail until the application is
restarted.

Is there anyone at all out there who can help me with this
strange behavior?

Thank you very much



Sat, 26 Feb 2005 17:36:39 GMT  
 QueryInterface fails
Fails with what error code?

I hope that at most one of the interfaces is dual. Otherwise
you simply asked for it...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> I have a very strange problem with a COM object.

> The COM Object class name is CMyComObject and it supports
> the two interfaces IMyComObject and IMutableMyComObject.

> When the system has been running for a couple of days
> successfully in release build (it never happens in debug
> build) this function starts to fail:
> pMyComObject->QueryInterface(IID_IMutableMyComObject,
> reinterpret_cast<void**>(&pMutableMyComObject));

> The pMyComObject pointer is created successfully on the
> line before this. So we know that it is successfully
> created and we know that it supports the interface. Still
> the QueryInterface fails. And once it has started to fail,
> it will continue to fail until the application is
> restarted.

> Is there anyone at all out there who can help me with this
> strange behavior?

> Thank you very much



Sun, 27 Feb 2005 01:57:49 GMT  
 QueryInterface fails
Thanks for the suggestions Alexander

We did remove the dual for all interfaces, but that didn't
help, even though I agree that it did allot of other
things better.

However, it seems like I have fixed the problem now; it
has been running for close to two days with the latest fix
now, and that is more than we ever have before.

It might be interesting for the rest of you to know what
was the problem.

In earlier versions of our software we did all our
initialization in the GUI-thread, but recently we moved
this to another thread that only handles the
initialization and some other tasks.

When we did this we moved the call to CoInitializeEx to
that thread as well, and that seems to be the problem.

CoInitializeEx must be called for each thread that wants
to use the COM library, so that solution was to call it in
the GUI-thread as well.

The strange part is that it worked anyway in debug-mode,
and it worked for a long time in release mode as well. So
it might be a warning to everybody that if you make this
mistake, you won't see it immediately.

Everything would be so much better if the COM libraries
was implemented so that you got an assertion or something
if they were called without CoInitializeEx, but
unfortunately, that is not the way it is...

Sincerely,
Christoffer

Quote:
>-----Original Message-----
>Fails with what error code?

>I hope that at most one of the interfaces is dual.
Otherwise
>you simply asked for it...

>--
>=====================================
>Alexander Nickolov
>Microsoft MVP [VC], MCSD

>MVP VC FAQ: http://www.mvps.org/vcfaq
>=====================================




- Show quoted text -

Quote:
>> I have a very strange problem with a COM object.

>> The COM Object class name is CMyComObject and it
supports
>> the two interfaces IMyComObject and IMutableMyComObject.

>> When the system has been running for a couple of days
>> successfully in release build (it never happens in
debug
>> build) this function starts to fail:
>> pMyComObject->QueryInterface(IID_IMutableMyComObject,
>> reinterpret_cast<void**>(&pMutableMyComObject));

>> The pMyComObject pointer is created successfully on the
>> line before this. So we know that it is successfully
>> created and we know that it supports the interface.
Still
>> the QueryInterface fails. And once it has started to
fail,
>> it will continue to fail until the application is
>> restarted.

>> Is there anyone at all out there who can help me with
this
>> strange behavior?

>> Thank you very much

>.



Tue, 08 Mar 2005 16:58:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. why queryinterface failed?

2. QueryInterface fails

3. Help: QueryInterface fails on 16-bit server

4. why failed queryinterface?

5. QueryInterface in C#

6. QueryInterface

7. QueryInterface in Managed code

8. Marshal.QueryInterface

9. QueryInterface in C

10. Real Time Data Server Failure -- (System.InvalidCastException) QueryInterface for interface IRTDUpdateEvent failed.

11. CoCreateInstance & QueryInterface

12. QueryInterface???

 

 
Powered by phpBB® Forum Software