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...
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
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 ...
May be this is the reason ?
How can I fix it?
Thank you...
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...
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)
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.
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 ?
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" <DrGE...@discussions.microsoft.com> wrote in message
news:0E678D9C-18A4-442E...@microsoft.com...
"Sheng Jiang[MVP]" wrote:
> all 3 components in the same thread?
>
No, in different processes. Already I have found my mistake.
Thank you