BUG: Type Library Importer Imports VARIANT_BOOL Field as Int16 (317203)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0

This article was previously published under Q317203

SYMPTOMS

When you import a structure that contains a field of type VARIANT_BOOL that is defined in a type library into a managed application, either by using Tlbimp.exe or by adding a reference to the COM server from Microsoft Visual Studio .NET, Tlbimp.exe or Visual Studio .NET converts this field into an int16 data type instead of a bool data type. This does not occur if you declare a method parameter as VARIANT_BOOL.

RESOLUTION

To resolve this problem, edit the interop assembly. To do this, follow these steps:
  1. At a command prompt, use Tlbimp.exe to create an interop assembly, as follows:

    TLBIMP.exe COMServer.dll /out:iop.COMServer.dll

  2. At a command prompt, use Ildasm.exe to generate the Microsoft intermediate language (MSIL) code for the interop assembly, as follows:

    ILDASM.exe iop.COMServer.dll /out:iop.COMServer.il

  3. Open Iop.comserver.il in Notepad or another text editor. Locate the structure and the field that you need to edit, and then change int32 to bool.
  4. At a command prompt, use the MSIL Assembler (ILASM) to create a new interop assembly, as follows:

    ILASM /dll iop.COMServer.il

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 Behavior

  1. Create a Microsoft Visual Basic 6.0 ActiveX dynamic-link library (DLL).
  2. Declare a structure and a function that resembles the following:
    Public Type TestStruct
      sc As Boolean
    End Type
    
    Public Function TestFunc(x As TestStruct, rc As Boolean)
    					
  3. Build the DLL, and then use Tlbimp.exe to generate the interop assembly.
  4. Use Ildasm.exe to view the generated MSIL.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:8/13/2003
Keywords:kbCOMInterop kbbug kbnofix KB317203