Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ATL\COM : QueryInterface returns 0x80004002 (E_NOINTERFACE).

930 views
Skip to first unread message

Dr.GEORGE

unread,
Sep 10, 2009, 8:15:01 AM9/10/09
to
Hello.

My application has a interface called IUser. I have added 2 new functions
and created new interface with name IUser2 :
[
object,
uuid(......-....-....-....-.....),
dual,
helpstring("IUser 2.0 Interface"),
pointer_default(unique)
]
interface IUser2 : IUser
{
[id(27), helpstring("method NewMethod1")]
HRESULT NewMethod1();

[id(28), helpstring("method NewMethod2")]
HRESULT NewMethod2();
};

This is written in MyIDLFile.idl file.

I have 3 components which must work with this new interface. In those
components a lot of code is written for work with the old interface IUser. I
have decided not to change it. If I need NewMethod1() or NewMethod2(), I just
call QueryInterface and get IUser2 interface, and invoke NewMethod1() or
NewMethod2(). I mean something like this :

CComPtr<IUser> user;
...
// Some old work with "user".
...
CComPtr<IUser2> user2;
if(SUCCEEDED(user->QueryInterface(IID_IUser2,(void**)&user2)))
{
user2->NewMethod1();
}

In all 3 components I have added MyIDLFile_i.c as an existing source file to
have IID_IUser2 declaration.

QueryInterface() works correctly in two of my components, but in third
component it returns 0x80004002 (E_NOINTERFACE).

Do you have any idea what can be the reason of such a behavior?
Any idea can be useful. I'm new in ATL/COM technologies.

Thank you...

Igor Tandetnik

unread,
Sep 10, 2009, 1:12:27 PM9/10/09
to
Dr.GEORGE <DrGE...@discussions.microsoft.com> wrote:
> My application has a interface called IUser. I have added 2 new
> functions and created new interface with name IUser2 :
>
> QueryInterface() works correctly in two of my components, but in third
> component it returns 0x80004002 (E_NOINTERFACE).

Did you update that component to derive from the new interface, and
mention it in its interface map?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Dr.GEORGE

unread,
Sep 11, 2009, 1:08:01 AM9/11/09
to
Hello Igor.
Before creation of IUser2, I have this in header file :


class ATL_NO_VTABLE CoUser :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CoUser, &CLSID_User>,
public IDispatchImpl<IUser, &IID_IUser, &LIBID_MyLib>
{
public:

// {{{ ATL Wizard
DECLARE_REGISTRY_RESOURCEID(IDR_COUSER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CoUser)
COM_INTERFACE_ENTRY(IUser)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
// }}}


After creation of IUser2, I have made some changes :

class ATL_NO_VTABLE CoUser :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CoUser, &CLSID_User>,
public IDispatchImpl<IUser2, &IID_IUser2, &LIBID_MyLib> // Changed line
{
public:

// {{{ ATL Wizard
DECLARE_REGISTRY_RESOURCEID(IDR_COUSER)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CoUser)
COM_INTERFACE_ENTRY(IUser)
COM_INTERFACE_ENTRY(IUser2) // Added line
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
// }}}


Must I do some other changes in this map?

Igor Tandetnik wrote :


>Did you update that component to derive from the new interface

Do you mean not working component? Does it need some other changes ? (except
adding MyIDLFile_i.c file)

Thank you ...

Dr.GEORGE

unread,
Sep 11, 2009, 2:28:01 AM9/11/09
to
Igor, I have found another interesting thing. I have tried to check values as
you had written in
http://www.eggheadcafe.com/conversation.aspx?messageid=31323618&threadid=31323615
And I have not found registry value for my IUser2 interface.

May be this is the reason ?

How can I fix it?

Thank you...

Dr.GEORGE

unread,
Sep 11, 2009, 3:36:04 AM9/11/09
to
I found my mistake. On my User.idl file, I have not added entry about new
interface. I mean it must be like this :
coclass User
{
[default] interface IUser;
interface IUser2; // Added line.
};

Now my program is working correctly. But now TypeLibs of IUser and IUser2
are different. Does it mean that they are in different components? Can this
born a error in future ?

Thank you...

Igor Tandetnik

unread,
Sep 11, 2009, 7:55:59 AM9/11/09
to
Dr.GEORGE wrote:
> I found my mistake. On my User.idl file, I have not added entry about
> new interface. I mean it must be like this :
> coclass User
> {
> [default] interface IUser;
> interface IUser2; // Added line.
> };
>
> Now my program is working correctly. But now TypeLibs of IUser and
> IUser2 are different.

What do you mean, TypeLibs are different?

Dr.GEORGE

unread,
Sep 11, 2009, 8:18:01 AM9/11/09
to
"Igor Tandetnik" wrote:
> What do you mean, TypeLibs are different?

Registry values of HKCR\Interface\GUID_OF_IUSER\TypeLib\(default)
and HKCR\Interface\GUID_OF_IUSER2\TypeLib\(default)

Igor Tandetnik

unread,
Sep 11, 2009, 8:35:52 AM9/11/09
to

It means they are in different typelibs. You have two different type
library files on your machine, with different LIBIDs. One contains just
the IUser, and the other (probably newer) both IUser and IUser2. You've
registered the newer one first, then the older one. So the older one
overwrote the registration of IUser to itself, but left IUser2 intact.

It is a bad idea to describe the same interface in more than one type
library. It's also not clear why you decided to change the LIBID.

Dr.GEORGE

unread,
Sep 11, 2009, 9:20:01 AM9/11/09
to
Thanks but how can I explicitly give LIBID for a interface ?

IDispatchImpl<IUser2, &IID_IUser2, &LIBID_MyLib>

line means that IUser2 must be in MyLib, am I right ?
And how can I give a LIBID for IUser ?

Igor Tandetnik

unread,
Sep 11, 2009, 9:34:57 AM9/11/09
to
Dr.GEORGE wrote:
> Thanks but how can I explicitly give LIBID for a interface ?

You don't give LIBID to an interface. You give it to the type library.
It's the uuid attribute on the library block in IDL.

Somehow you have two IDL files lying around, with different LIBIDs, both
defining the same IUser interface. Pick one, and stick with it.

Dr.GEORGE

unread,
Sep 12, 2009, 2:35:01 AM9/12/09
to
Thank you very much, that was great help.

Sheng Jiang[MVP]

unread,
Sep 14, 2009, 10:38:07 AM9/14/09
to

all 3 components in the same thread?


"Dr.GEORGE" <DrGE...@discussions.microsoft.com> wrote in message
news:0E678D9C-18A4-442E...@microsoft.com...

Dr.GEORGE

unread,
Sep 15, 2009, 1:48:01 AM9/15/09
to

"Sheng Jiang[MVP]" wrote:

> all 3 components in the same thread?
>

No, in different processes. Already I have found my mistake.

Thank you

0 new messages