Microsoft KB Archive/214483

= PRB: Implements Statement Requires Interface Derived from IDispatch or IUnknown =

Article ID: 214483

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q214483



SYMPTOMS
If you create an interface, which is derived from an interface other than IUnknown or IDispatch, this interface cannot be implemented using the Implements statement in Visual Basic. Doing so causes the following compile error:

Compiler error

Bad interface for Implements: interface is derived from another pure interface with non-restricted methods.



CAUSE
In the Visual Basic documentation for "Implements Statement", the following is stated:

"Visual Basic does not implement derived classes or interfaces."



RESOLUTION
Change your interface definition of the class, deriving it from either IDispatch or IUnknown.



STATUS
This behavior is by design.



Create an ATL COM project in Visual C++
 Create a new Visual C++ project named ATLTest specifying the project category to be ATL COM AppWizard. In the ATL COM AppWizard dialog box, select "Dynamic Link Library" as the server type, and then click Finish. From the Visual C++ Insert menu, select New Class. In the New Class dialog box, type "CMyobj" as the class name, specify "Dual" as the interface type, and increase the "Number of interfaces" to 2. Two interfaces named IMyobj and IMyobjInt2 appear in the interface Names dialog box. Click OK. Select the ClassView tab, expand the ATLTest classes node, right-click the "IMyobj" interface, and select Add Method. In the Add Method to Interface dialog box, type "Test" in the Method Name field and click OK.</li> Right-click the "IMyobjInt2" interface and select Add Method. In the Add Method to Interface dialog box, type "Bar" in the Method Name field and click the OK button.</li>  Click the FileView tab, expand the ATLTest files node, and then expand the Source Files node. Open the ATLTest.idl file and locate the interface definition for IMyobjInt2. Delete the existing interface and replace it with the following: interface IMyobjInt2 : IMyobj {        [id(2), helpstring("method Bar")] HRESULT Bar; };                   </li>  Expand the Header Files node and open the Myobj.h file. Comment out the following line from the "CMyobj" class definition: public IDispatchImpl<IMyobj, &IID_IMyobj, &LIBID_ATLTESTLib>, </li> From the Build menu, choose Rebuild All to create the DLL.</li></ol>

Create a Visual Basic Client Program
<ol> Create a Visual Basic Standard EXE project. Form1 is created by default.</li> From the Project menu, choose References, and add a reference to ATLTest.</li> From the Project menu, choose Add Class Module to add Class1 to the project.</li>  Paste the following code in the General Declarations section of Class1: Implements IMyobjInt2 </li> Run the project. The following error occurs:

Compiler error

Bad interface for Implements: interface is derived from another pure interface with non-restricted methods.

</li></ol>

Steps to Resolve the Problem
<ol> Close the Visual Basic client program.</li> Open the ATLtest project in Visual C++.</li> In the FileView of the project, open the ATLTest.idl file, find the interface "IMyobjInt2" definition, and replace the reference to IMyobj with IDispatch.</li> Open the Myobj.h file and remove the comment you added to the "CMyobj" class definition:</li> From the Build menu, choose Build All.</li> Go back to the Visual Basic client program. If you attempt to run the project at this point you will receive the following error message:

Compiler error

Object module needs to implement 'Bar' for interface 'IMyobjInt2'

</li> Drop down the left hand combo box of Class1's Code window and select IMyobjInt2 to implement the Bar method. Then the sample no longer generates an error.</li></ol>

Keywords: kbprb KB214483

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.