Wrapper for unmanaged virtual methods probs

G

Guest

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 --
Boolean DoIt2 (Void) { return m_MyClass->DoIt2(); } ; // returns false --
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 ;
} ;
 
W

William DePalo [MVP VC++]

Carl said:
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
 
G

Guest

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?
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top