473,396 Members | 2,030 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,396 software developers and data experts.

Wrapper for unmanaged virtual methods probs


Hello,

I noticed an unexplained (for me) behaviour while wrapping unmanaged virtual
methods.

This is the test situation:
An unmanaged class has four methods defined DoIt1 .. DoIt4. Each method just
returns false.
DoIt3 and DoIt4 are virtual methods defined in the base class MyBase of my
unmanaged code.
MyClass is an unmanaged class I derived from MyBase.

MMyClass is the managed wrapper class for MyClass.

I only get the correct return value, when I explicitly give the name of
MyClass when calling the DoItx method. See code parts below.
Does anyone know the reason?

Thank you
Carl
---------------------------------------------------------

class __declspec(dllexport) MyBase
{
public:
bool DoIt2 (void) { return false ; }
virtual bool DoIt3 (void) { return false ; }
virtual bool DoIt4 (void) = 0 ;
} ;

---------------------------------------------------------

class __declspec(dllexport) MyClass : public MyBase
{
public:
bool DoIt1 (void) { return false ; }
bool DoIt3 (void) { return false ; }
bool DoIt4 (void) { return false ; }
} ;

---------------------------------------------------------

#include "..\UnManagedCode\MyClass.h"

using namespace System ;

public __gc class MMyClass

{

public:
MMyClass (Void) { m_MyClass = new MyClass() ; } ;
~MMyClass (Void) { delete m_MyClass ; } ;

Boolean DoIt1 (Void) { return m_MyClass->DoIt1(); } ; // returns false --
Ok. Boolean DoIt2 (Void) { return m_MyClass->DoIt2(); } ; // returns false -- Ok. Boolean DoIt3 (Void) { return m_MyClass->DoIt3(); } ; // returns true -- !!!!!!!! Oops. Boolean DoIt4 (Void) { return m_MyClass->DoIt4(); } ; // returns true -- !!!!!!!! Oops.


Boolean DoIt5 (Void) { return m_MyClass->MyClass::DoIt1(); } ; // returns
false -- > Ok.
Boolean DoIt6 (Void) { return m_MyClass->MyClass::DoIt2(); } ; // returns
false -- > Ok.
Boolean DoIt7 (Void) { return m_MyClass->MyClass::DoIt3(); } ; // returns
false -- > Ok.
Boolean DoIt8 (Void) { return m_MyClass->MyClass::DoIt4(); } ; // returns
false -- > Ok.

private:
MyClass __nogc * m_MyClass ;
} ;
Nov 17 '05 #1
7 1185
"Carl" <Ca**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
I noticed an unexplained (for me) behaviour while wrapping unmanaged
virtual
methods.

This is the test situation:
An unmanaged class has four methods defined DoIt1 .. DoIt4. Each method
just
returns false.
...
I only get the correct return value, when I explicitly give the name of
MyClass when calling the DoItx method. See code parts below.
Does anyone know the reason?


Well, there is a problem marshalling booleans between managed and unmanaged
code. I'm not sure if it is the cause of your grief. But you can insert this
line

_asm xor eax, eax

just before this line

return false;

in your code.

If that doesn't help you, please post again and perhaps someone will have a
better idea.

Regards,
Will

Nov 17 '05 #2
You are describing the so called virtual bool bug. The next VS service pack
will fix this problem. You can also download a hotfix from [1]

Marcus Heege

[1] http://support.microsoft.com/kb/823071/en-us
Nov 17 '05 #3
"Marcus Heege" <NO****@heege.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
You are describing the so called virtual bool bug. The next VS service
pack will fix this problem. You can also download a hotfix from [1]

Marcus Heege

[1] http://support.microsoft.com/kb/823071/en-us


Just for the sake of completeness, note that a method does not have to be
virtual to exhibit this behavior.

Regards,
Will
Nov 17 '05 #4
See http://www.codeproject.com/buglist/virtualboolbug.asp

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Carl" <Ca**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...

Hello,

I noticed an unexplained (for me) behaviour while wrapping unmanaged
virtual
methods.

This is the test situation:
An unmanaged class has four methods defined DoIt1 .. DoIt4. Each method
just
returns false.
DoIt3 and DoIt4 are virtual methods defined in the base class MyBase of my
unmanaged code.
MyClass is an unmanaged class I derived from MyBase.

MMyClass is the managed wrapper class for MyClass.

I only get the correct return value, when I explicitly give the name of
MyClass when calling the DoItx method. See code parts below.
Does anyone know the reason?

Thank you
Carl
---------------------------------------------------------

class __declspec(dllexport) MyBase
{
public:
bool DoIt2 (void) { return false ; }
virtual bool DoIt3 (void) { return false ; }
virtual bool DoIt4 (void) = 0 ;
} ;

---------------------------------------------------------

class __declspec(dllexport) MyClass : public MyBase
{
public:
bool DoIt1 (void) { return false ; }
bool DoIt3 (void) { return false ; }
bool DoIt4 (void) { return false ; }
} ;

---------------------------------------------------------

#include "..\UnManagedCode\MyClass.h"

using namespace System ;

public __gc class MMyClass

{

public:
MMyClass (Void) { m_MyClass = new MyClass() ; } ;
~MMyClass (Void) { delete m_MyClass ; } ;

Boolean DoIt1 (Void) { return m_MyClass->DoIt1(); } ; // returns false --
Ok.

Boolean DoIt2 (Void) { return m_MyClass->DoIt2(); } ; // returns false --
Ok.

Boolean DoIt3 (Void) { return m_MyClass->DoIt3(); } ; // returns true --
!!!!!!!! Oops.

Boolean DoIt4 (Void) { return m_MyClass->DoIt4(); } ; // returns true --
!!!!!!!! Oops.


Boolean DoIt5 (Void) { return m_MyClass->MyClass::DoIt1(); } ; // returns
false -- > Ok.
Boolean DoIt6 (Void) { return m_MyClass->MyClass::DoIt2(); } ; // returns
false -- > Ok.
Boolean DoIt7 (Void) { return m_MyClass->MyClass::DoIt3(); } ; // returns
false -- > Ok.
Boolean DoIt8 (Void) { return m_MyClass->MyClass::DoIt4(); } ; // returns
false -- > Ok.

private:
MyClass __nogc * m_MyClass ;
} ;

Nov 17 '05 #5

Thanks a lot. The mentioned articles described my problem.

But I'm still shocked and very Very VERY concerned about other bugs like
this in my code which I don't know about yet.

The workaround seems not to be easy if you can't change the unmanaged code.
I will see if I can get the Microsoft hotfix.

Is there a list somewhere about all the bugs you better should know about?

Nov 17 '05 #6
It's been fixed in VC++ 2005 (as of Beta 2)

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"Carl" <Ca**@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...

Thanks a lot. The mentioned articles described my problem.

But I'm still shocked and very Very VERY concerned about other bugs like
this in my code which I don't know about yet.

The workaround seems not to be easy if you can't change the unmanaged
code.
I will see if I can get the Microsoft hotfix.

Is there a list somewhere about all the bugs you better should know about?

Nov 17 '05 #7

Good to know, but I don't see that as an acceptable solution for the problem.

"I'm not going to buy a new car just because the cigarette lighter is broken."
"Nishant Sivakumar" wrote:
It's been fixed in VC++ 2005 (as of Beta 2)


Nov 17 '05 #8

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

Similar topics

1
by: | ov | last post by:
Hi, My application includes a class library which has both managed C++ and unmanaged C++ code. The unmanaged C++ code includes only one class with both virtual methods and non-virtual methods....
2
by: JRoe | last post by:
Hello, I am beside myself with this problem. I need to access unmanged C++ code in a C# environment. I have created a managed C++ wrapper that wraps the unmanaged class. When I call the...
0
by: Vasco Lohrenscheit | last post by:
Hello, I have problems with pointers to unmanaged classes as parameters for virtual methods, and then overwriting the virtual methods in other assemblies: //GUI.dll #include...
1
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an...
9
by: WithPit | last post by:
I am trying to create an Managed C++ Wrapper around an unmanaged library which contains C++ code. Some of the unmanaged methods returns an returntype which is of the abstract base type (for...
3
by: WithPit | last post by:
I am trying to create an managed wrapper but have some problems with it by using abstract classes. In my unmanaged library code i had the following three classes with the following hierarchy ...
4
by: bidalah | last post by:
Hi all, Basically I need to create a managed wrapper for the class "A" below: class A : public CModule { public: A(B& bees); virtual ~A();
2
by: =?Utf-8?B?cGh5cw==?= | last post by:
I need to write a C# application that uses unmanaged C++ code. I created a C++/CLI wrapper to C++ code and encountered the following problem. Any time I try to instantiate a wrapper in C#...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.