Microsoft KB Archive/327097

= BUG: Visual C++ .NET Compiler Generates Two Different Native Types for the Same Boolean Return Type =

Article ID: 327097

Article Last Modified on 9/27/2005

-

APPLIES TO


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

-



This article was previously published under Q327097



SYMPTOMS
The Visual C++ .NET compiler generates both NATIVE_TYPE_U1 and NATIVE_TYPE_VARIANTBOOL for the same Boolean return type that is marked with MarshalAs(UnmanagedType::VariantBool).



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
 In Visual C++ .NET, create a new Managed C++ Application project that is named TestBoolean .  Double-click the TestBoolean.cpp file in Solution Explorer and then replace the code in that file with the following code: // This is the main project file for the Visual C++ Application project that is // generated by using an Application Wizard.


 * 1) include &quot;stdafx.h&quot;


 * 1) using 
 * 2) include 

using namespace System;

__gc class TestBoolean { public: [returnvalue:System::Runtime::InteropServices::MarshalAs (System::Runtime::InteropServices::UnmanagedType::VariantBool)] bool RetValBoolean ([System::Runtime::InteropServices::MarshalAs   (System::Runtime::InteropServices::UnmanagedType::VariantBool)] bool b)    { return b;   } };

int _tmain(void) {   TestBoolean *test = new TestBoolean; Console::WriteLine(test->RetValBoolean(true)); return 0; }                        Press CTRL+SHIFT+B to build the project.  From the command prompt, type the following:  c:\>ildasm.exe /adv This starts ildasm in the advanced mode.  Open TestBoolean.exe in ildasm.

</li>  On the View menu, click Metalnfo and then click Show!.

Examine the metadata that is produced. You see that the compiler emits two different native types for the return value. Global fields ---

Global MemberRefs ---

TypeDef #1 ---   TypDefName: TestBoolean  (02000002) Flags    : [NotPublic] [AutoLayout] [Class] [AnsiClass]  (00000000) Extends  : 01000008 [TypeRef] System.Object Method #1 ---       MethodName: RetValBoolean (06000003) Flags    : [Public] [ReuseSlot]  (00000006) RVA      : 0x00001000 ImplFlags : [IL] [Managed] (00000000) CallCnvntn: [DEFAULT] hasThis ReturnType: Boolean 1 Arguments Argument #1: Boolean 3 Parameters (0) ParamToken : (08000001) Name : flags: [HasFieldMarshal]  (00002000) NATIVE_TYPE_U1 (0) ParamToken : (08000002) Name : flags: [HasFieldMarshal]  (00002000) NATIVE_TYPE_VARIANTBOOL (1) ParamToken : (08000003) Name : b flags: [HasFieldMarshal] (00002000) NATIVE_TYPE_VARIANTBOOL </li></ol>

Keywords: kbbug kbnofix kbqfe kbcominterop kbhotfixserver KB327097

-

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

© Microsoft Corporation. All rights reserved.