Symptoms
When in a unmanaged application that uses multiple inheritance as Event_RecEcess (
__unhook) When a Native Events will fail. __unhook will return 1 (indicating that there is no successful unhathook. After the application ends, the Native Event mechanism has caused memory leakage.
Cause This problem occurs in the case of an inheritance class in an event's recipient (event_receiver). In the unhook, the EVENT injection code cannot be correctly compared the member function pointer.
Workaround
This question can be reproduced using the following code:
#include
Class a {int a;
Class B {Int B;
[Event_source] class csource {public: __event void myevent (int nvalue);
[Event_Receiver] Class Creceiver: Public A, PUBLIC B // Multi Inheritance {PUBLIC: Void myHandler1 ("MyHandler1 Was Called With Value% D. / N", NValue);}
Void myHandler2 (int nvalue) {Printf ("MyHandler2 Was Called With Value% D. / N", NValue);}};
INT main () {csource source; creceiver receiver; CRECEIVER Receiver;
__unhook (& CSource :: MyEvent, & source, & CReceiver :: MyHandler2, & receiver); __hook (& CSource :: MyEvent, & source, & CReceiver :: MyHandler1, & receiver); __raise source.MyEvent (1); __unhook (& CSource :: MyEvent, & source , & CReceiver :: MyHandler1, & receiver); // failure __hook (& cSource :: MyEvent, & source, & CReceiver :: MyHandler2, & receiver); __raise source.MyEvent (2); __unhook (& cSource :: MyEvent, & source, & CReceiver :: MyHandler2 , & receiver; // failed}
operation result
MyHandler1 Was Called with value 1.myhandler2 Was Called with value 2.myhandler1 Was Called with value 2.
MyHandler2 is not correct unhook.
The Information in this Article Applies TO:
Microsoft Visual C .NET (2002) Microsoft Visual C .NET (2003) Visual C 2005 Express Edition Beta