473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with bool in unmanaged/managed interop

Ian
When I have an unmanaged class (compiled without /clr or
with #pragma unmanaged) with return type virtual bool,
the return value always comes out true when called in
managed code. Only happens with virtual and bool. Sample
code below.

Is anyone aware of a fix, workaround, etc?

Sample Code:
/*-----------------------------------------------------*/
#pragma unmanaged

struct test1
{
bool value() { return false; }
};

struct test2
{
virtual bool value() { return false; }
};

struct test3
{
virtual unsigned char value() { return false; }
};

struct test4
{
virtual bool value() { return true; }
};

struct test6
{
bool value();
};

bool test6::value() { return false; }

template<class T>
bool value( T * t ) { return t->value(); }

#pragma managed

#using <mscorlib.dll>

__nogc struct test5
{
virtual bool value() { return false; }
};

int main()
{
test1 *t1 = new test1();
test2 *t2 = new test2();
test3 *t3 = new test3();
test4 *t4 = new test4();
test5 *t5 = new test5();
test6 *t6 = new test6();

System::Console::WriteLine("t1 value: {0} ;
should be {1}", __box(t1->value()), __box(value(t1)));
System::Console::WriteLine("t2 value: {0} ;
should be {1}", __box(t2->value()), __box(value(t2)));
System::Console::WriteLine("t3 value: {0} ;
should be {1}", __box(bool(t3->value())), __box(value
(t3)));
System::Console::WriteLine("t4 value: {0} ;
should be {1}", __box(t4->value()), __box(value(t4)));
System::Console::WriteLine("t5 value: {0} ;
should be {1}", __box(t5->value()), __box(value(t5)));
System::Console::WriteLine("t6 value: {0} ;
should be {1}", __box(t6->value()), __box(value(t6)));
System::Console::WriteLine( "Done" );

while(1);

}
/*-----------------------------------------------------*/
Nov 16 '05 #1
2 2210
This is a known bug. One possible work around is to return a BOOL (int)

--
Regards,
Nish [VC++ MVP]

"Ian" <ib*******@hotmail.com> wrote in message
news:09****************************@phx.gbl...
When I have an unmanaged class (compiled without /clr or
with #pragma unmanaged) with return type virtual bool,
the return value always comes out true when called in
managed code. Only happens with virtual and bool. Sample
code below.

Is anyone aware of a fix, workaround, etc?

Sample Code:
/*-----------------------------------------------------*/
#pragma unmanaged

struct test1
{
bool value() { return false; }
};

struct test2
{
virtual bool value() { return false; }
};

struct test3
{
virtual unsigned char value() { return false; }
};

struct test4
{
virtual bool value() { return true; }
};

struct test6
{
bool value();
};

bool test6::value() { return false; }

template<class T>
bool value( T * t ) { return t->value(); }

#pragma managed

#using <mscorlib.dll>

__nogc struct test5
{
virtual bool value() { return false; }
};

int main()
{
test1 *t1 = new test1();
test2 *t2 = new test2();
test3 *t3 = new test3();
test4 *t4 = new test4();
test5 *t5 = new test5();
test6 *t6 = new test6();

System::Console::WriteLine("t1 value: {0} ;
should be {1}", __box(t1->value()), __box(value(t1)));
System::Console::WriteLine("t2 value: {0} ;
should be {1}", __box(t2->value()), __box(value(t2)));
System::Console::WriteLine("t3 value: {0} ;
should be {1}", __box(bool(t3->value())), __box(value
(t3)));
System::Console::WriteLine("t4 value: {0} ;
should be {1}", __box(t4->value()), __box(value(t4)));
System::Console::WriteLine("t5 value: {0} ;
should be {1}", __box(t5->value()), __box(value(t5)));
System::Console::WriteLine("t6 value: {0} ;
should be {1}", __box(t6->value()), __box(value(t6)));
System::Console::WriteLine( "Done" );

while(1);

}
/*-----------------------------------------------------*/

Nov 16 '05 #2
Jochen Kalmbach wrote:
This is a known bug for over 1 year!!!
I reported it 12.04.2002.


FYI: It is fixed in the next version of Visual C++.

--
Brandon Bray Visual C++ Compiler
This posting is provided AS IS with no warranties, and confers no rights.
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
1
by: Nadav | last post by:
Hi, Introduction: ********************* I am writing a mixed mode application I have a COM module and a .NET module that communicate with each other. The COM exposes a custom sink interface,...
1
by: Zapbbx | last post by:
I have a 3rd party application that can reference external dll's. The dll's have to be written in unmanaged code with an exported function I can reference and call. I would like it to call a C# dll...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
4
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
3
by: Mali Guven | last post by:
Hello, I have a native DLL (written in C) which is supposed to call a managed DLL (was written in C#, and an entry point was injected modifying the ildasm'd code). The exectuable calls the...
0
by: Nadav | last post by:
Hi, Introduction: I have developed an interop project built of an unmanaged COM object and a ..NET WinForm application, the WinForm Application implement the user interface while the unmanaged...
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.