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



The information in this article applies to:

  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ .NET (2003)

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("MyTypeLib.tlb");
				

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

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

    To do this, follow these steps:
    1. Create a new Microsoft Visual C# class library project named MyTypeLib that defines a new managed interface IMyInterface.
    2. In the project properties, select the Configuration Properties group, click the Build tab, and then set Register for COM interop to True.
  2. Create a new active template library (ATL) project (for example, ComApp), and then add a simple object to the project (for example, MyComClass).
  3. Right-click MyComClass, click Add, and then click Implement Interface.
  4. In the dialog box, click File, locate and select the MyTypeLib.tlb file that you generated in step 1.
  5. 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.
  6. Add your implementation of a method of IMyInterface, and then compile the project.
  7. 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.
  8. 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.

Modification Type:MajorLast Reviewed:4/11/2003
Keywords:kbbug kbpending kbreadme KB307172