How to wrap virtual functions?
-
Consider a library (unmanaged) exports a class. the class is as follows.
class A { public: virtual void funcA() { //do something } void DoProcessing() { // Do stuff funcA(); // Do Stuff } }
Now in native, If i have to override funcA it would be asclass DA : public A { public: virtual void funcA() { // related processing here. } }
Now if i create an object of DA, and call DoProcessing() , funcA() in DA would be called. Now if I write a managed wrapper over class A asclass _gc MngdA { private: A __nogc* m_pA; public: void DoProcessing() { m_pA->DoProcessing(); } }
No if I inherit from MngdA, i dont have any path to override the virtual functions. This means DoProcessing() will always call the funcA() in class A. I need a mechanism, so that this virtual function call from the native could could be riuted out into managed code and be able to override it from clr languages. -
Consider a library (unmanaged) exports a class. the class is as follows.
class A { public: virtual void funcA() { //do something } void DoProcessing() { // Do stuff funcA(); // Do Stuff } }
Now in native, If i have to override funcA it would be asclass DA : public A { public: virtual void funcA() { // related processing here. } }
Now if i create an object of DA, and call DoProcessing() , funcA() in DA would be called. Now if I write a managed wrapper over class A asclass _gc MngdA { private: A __nogc* m_pA; public: void DoProcessing() { m_pA->DoProcessing(); } }
No if I inherit from MngdA, i dont have any path to override the virtual functions. This means DoProcessing() will always call the funcA() in class A. I need a mechanism, so that this virtual function call from the native could could be riuted out into managed code and be able to override it from clr languages.Well, C++/CLI also has virtual functions. As long as your managed wrappers also have the same inheritance hierarchy. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Well, C++/CLI also has virtual functions. As long as your managed wrappers also have the same inheritance hierarchy. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
I think u dint got my question right. I have updated the question with further explanation if u could plz have a look. Rahim Rattani Karachi - Pakistan
-
Consider a library (unmanaged) exports a class. the class is as follows.
class A { public: virtual void funcA() { //do something } void DoProcessing() { // Do stuff funcA(); // Do Stuff } }
Now in native, If i have to override funcA it would be asclass DA : public A { public: virtual void funcA() { // related processing here. } }
Now if i create an object of DA, and call DoProcessing() , funcA() in DA would be called. Now if I write a managed wrapper over class A asclass _gc MngdA { private: A __nogc* m_pA; public: void DoProcessing() { m_pA->DoProcessing(); } }
No if I inherit from MngdA, i dont have any path to override the virtual functions. This means DoProcessing() will always call the funcA() in class A. I need a mechanism, so that this virtual function call from the native could could be riuted out into managed code and be able to override it from clr languages.You'd need managed wrappers for both base and derived classes for this particular scenario. Regards, Nish
My blog : Nish’s thoughts on MFC, C++/CLI and .NET