Microsoft KB Archive/317203

= BUG: Type Library Importer Imports VARIANT_BOOL Field as Int16 =

Article ID: 317203

Article Last Modified on 2/23/2007

-

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:  At a command prompt, use Tlbimp.exe to create an interop assembly, as follows:

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

 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

 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. 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.



Steps to Reproduce Behavior
 Create a Microsoft Visual Basic 6.0 ActiveX dynamic-link library (DLL).</li>  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) </li> Build the DLL, and then use Tlbimp.exe to generate the interop assembly.</li> Use Ildasm.exe to view the generated MSIL.</li></ol>

<div class="references_section">