mysterious DISP_E_UNKNOWNNAME (only default interface?)
Quote:
>Here is a brief description of the problem:
>Platform NT Workstation 4.0
>Development Environment VC++ Studio 5.0 (Enterprise version)
>I created an ATL object with two dual interfaces Itest2 and Itest3
>with one of them marked "default". Itest2 has a method called
>setValue() and Itest3 has a method called getValue().
>I have a C++ MFC client, from where I call QueryInterface() with
>IID_IDispatch as an argument on both the interfaces. This call
>succeeds. After that, GetIDsOfNames() succeeds only for "setValue"
>(which is the name of the method in the default interface) and not for
>"getValue" (which is the name of the method in the non-default
>interface). The error code I get is DISP_E_UNKNOWNNAME
>Does it mean that I can only get the default interface from my C++ or
>VB client and not the other one? What's going on here?
Well, when you have multiple IDispatch-based interfaces on an object, only
one of them can be returned by a QI for IID_IDispatch - and it better be the
same one every time. That's what the [default] attribute tells the MIDL
compiler.
If you want to get the Itest3 interface, you have to QI specifically for
IID_Itest3. Then you can call get_Value. That's why most objects only
provide one IDispatch-based interface; it's less of a headache. There's no
general reason(though you might have a specific one) to have multiple
dispinterfaces in the first place.
--
John C. Barstow
Microcrafts, Inc.
http://www.*-*-*.com/
425-250-0000