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

Article translations Article translations
Article ID: 327097 - View products that this article applies to.
This article was previously published under Q327097
Expand all | Collapse all

On This Page

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual C++ .NET, create a new Managed C++ Application project that is named TestBoolean.
  2. 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.
    
    #include "stdafx.h"
    
    #using <mscorlib.dll>
    #include <tchar.h>
    
    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;
    }
    						
  3. Press CTRL+SHIFT+B to build the project.
  4. From the command prompt, type the following:
    	c:\>ildasm.exe /adv
    						
    This starts ildasm in the advanced mode.
  5. Open TestBoolean.exe in ildasm.

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

Properties

Article ID: 327097 - Last Review: September 27, 2005 - Revision: 1.6
APPLIES TO
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
Keywords: 
kbhotfixserver kbqfe kbbug kbcominterop kbnofix KB327097

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com