Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bool return type from virtual method

665 views
Skip to first unread message

Jacob Yang

unread,
Nov 7, 2002, 3:23:47 AM11/7/02
to
Hi Roy,

I am trying to confirm this issue. I will contact you as soon as possible.

Best regards,

Jacob Yang
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2002 Microsoft Corporation. All rights
reserved

Jochen Kalmbach

unread,
Nov 7, 2002, 8:04:55 AM11/7/02
to
Jacob Yang wrote:

> I am trying to confirm this issue. I will contact you as soon as
> possible.

Do you mean the vurtual bool bug in Managed C++ ?:


This is a known bug... it will be fixed in the next version...

Here is the support number of the
corresponding MS support question: SRD020412600033


<code>
#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// The following is unmanaged code (it can also be a library)
#pragma unmanaged
class Unmanaged
{
public:
virtual bool AreYouOk();
};

bool Unmanaged::AreYouOk()
{
return false;
}


// the following is managed code
#pragma managed
// This is the entry point for this application
int _tmain(void)
{
Unmanaged *um = new Unmanaged();
if (um->AreYouOk() == true)
Console::WriteLine(S"Yes, I am fine!");
else
Console::WriteLine(S"No!");
return 0;
}
</code>


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/useritems/leakfinder.asp

Bobby Mattappally [MS]

unread,
Nov 8, 2002, 8:23:07 PM11/8/02
to

This is a known bug.

Workaroud is to set the EAX register to 255 or less before the return
'false' from unmanaged to managed code (one way to do this):

#pragma unmanaged
int ForceEAX()
{
//return 256; //A::F() returns incorrect true
return 255; //A::F() returns correct false
}

bool A::F()
{
ForceEAX();
return false;
}

The lower byte of EAX is handled properly, it's only when one of the upper
24 bits is non-zero that the return value is bogus.

Hope this helps.

Thank you,
Bobby Mattappally
Microsoft VC++/C# Team

This posting is provided "AS IS" with no warranties, and confers no rights.


>
>Hi,
>
>This is a bug in VC7.
>
>I've got an unmanaged(native) C++ class which has a
>virtual method that returns bool. I've got a managed C++
>class, in a different project, that calls the unmanaged
>method. Regardless of what the return value of the
>unmanaged method is (true or false) the calling managed
>method always recieves true. If I remove the "virtual"
>keyword in the unmanaged method declaration, it behaves
>as expected.
>
>Someone already posted a similar issue previously in this
>newsgroup but I'm not sure what the resolution was. Is
>there a patch that I could download for this? Is this
>gonna be fixed in the next service pack (and when)?
>
>Regards
>
>Roy Alingcastre
>

0 new messages