Microsoft KB Archive/307172

= BUG: ATL Implement Interface Wizard Does Not Insert Imported Interface Information into a COM Type Library =

Article ID: 307172

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



This article was previously published under Q307172



SYMPTOMS
When you use the Implement Interface wizard in an Active Template Library (ATL) project, and you select an interface from another type library, the code that the wizard generates does not include the definition of the implemented interface. As a result, when you call this ATL COM object from a managed client, the call may not succeed.



CAUSE
If the specific type library is registered, Microsoft COM clients can call this ATL COM object. A managed client, however, may fail under certain circumstances because the COM Interop assembly that is generated from this COM server does not contain the metadata for the external interface. As a result, you cannot use late bound methods (for example, MethodInfo) to successfully call methods from this interface.

NOTE: You also cannot call methods from this interface on a remoting proxy.



RESOLUTION
To work around this problem, paste the following code in the library block of the ATL project interface definition language (.idl) file: importlib(&quot;MyTypeLib.tlb&quot;);



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Create a Microsoft Visual Studio .NET project that defines an interface, and then generate the corresponding .tlb file.

To do this, follow these steps:  Create a new Microsoft Visual C# class library project named MyTypeLib that defines a new managed interface IMyInterface. In the project properties, select the Configuration Properties group, click the Build tab, and then set Register for COM interop to True.  Create a new active template library (ATL) project (for example, ComApp), and then add a simple object to the project (for example, MyComClass).</li> Right-click MyComClass, click Add, and then click Implement Interface.</li> In the dialog box, click File, locate and select the MyTypeLib.tlb file that you generated in step 1.</li> Select the managed interface that you want to implement, in this case IMyInterface. The wizard generates the code to implement the methods from this interface.</li> Add your implementation of a method of IMyInterface, and then compile the project.</li> Start the OLE/COM Object Viewer and load the ATL project's output as a typelib. Note that it does not contain type information for IMyInterface.</li> Run the TlbImp.exe file on the ATL project's output, and then load the generated assembly in the MSIL Disassembler Ildasm.exe file. No metadata information is available for the IMyInterface methods.</li></ol>

Additional query words: MethodInfo kbreadme

Keywords: kbbug kbreadme kbpending KB307172

-

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

© Microsoft Corporation. All rights reserved.