473,813 Members | 4,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dlle xport) MyBase
{
public:
bool DoIt2 (void) { return false ; }
virtual bool DoIt3 (void) { return false ; }
virtual bool DoIt4 (void) = 0 ;
} ;

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

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

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

#include "..\UnManagedCo de\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 1205
"Carl" <Ca**@discussio ns.microsoft.co m> wrote in message
news:92******** *************** ***********@mic rosoft.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.n et> wrote in message
news:%2******** ********@TK2MSF TNGP15.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**@discussio ns.microsoft.co m> wrote in message
news:92******** *************** ***********@mic rosoft.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(dlle xport) MyBase
{
public:
bool DoIt2 (void) { return false ; }
virtual bool DoIt3 (void) { return false ; }
virtual bool DoIt4 (void) = 0 ;
} ;

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

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

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

#include "..\UnManagedCo de\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**@discussio ns.microsoft.co m> wrote in message
news:04******** *************** ***********@mic rosoft.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
1652
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. When I use the debugger I am able to step into methods that are non-virtual, however, when I try to step into methods which are virtual I receive the following message: "There aren't source code avalaible for the current location". The unmanaged...
2
2215
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 constructor, it is returning undefined. Here is an example: Unmanaged C++ class Map_Interface
0
1290
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 "../Plugin/iPlugin.h" //unmanaged plugin interface header public __gc PluginGui : public Windows::Forms::Form
1
7163
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 Initialize function in the unmanaged library) crashes everytime I call it. Initialize calls another function 'GetInstance' (a static member function of a class) which looks something like: CLibConfig& CLibConfig::GetInstance()
9
2427
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 example unmanagedObject). How can i convert this to the managed abstract basetype? Hope somebody can help me Thanx
3
1816
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 Referenced (class) Object (abstract class, inheriting from referenced) Node (class, inheriting from object)
4
1078
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
7259
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# application the program crashes with an error "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll, Additional information: The specified module could not be found. (Exception from HRESULT: 0x8007007E)". C#...
3
4713
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 application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10665
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10406
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10420
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.