G
Guest
Serious bug discovered in VC .NET (2002) compiler.
Example below should work if I understand the Microsoft documentation
correctly.
Hopfelly there is some compiler upgrade that fixes this bug?
[event_source(native)]
class CTubeDev {
....
__event void OnEnableControls(const BOOL abEnable);
....
};
[event_receiver(native)]
class CPowerDlg : public CDialog {
....
void DoEnableControls(const BOOL abEnable);
....
}
Somewhere in CPowerDlg I call the hook function only once:
__hook(&CTubeDev::OnEnableControls,m_pDev, &CPowerDlg:oEnableControls);
I take care that the __hook is only called once and no __unhook is called
before a __hook.
So when I call OnEnableControls() from a CTubeDev instance, then the
DoEnableControls() is correctly called, processed but when returning back to
the CTubeDev instance I get an access violation.
Reverse engeneering suggests that there is a node->next pointer that is not
initialized to NULL in the events list handler when the class is created.
A very dirty fix so far to make this system work as it should, is to try to
find the hidden generated attribute created by the __event keyword, and
initialize this to NULL in the constructor, like this.
//--------------------------------------------------------------------
CTubeDev::CTubeDev()
{
__eventHandlerList_CTubeDev_OnEnableControls=NULL;
.....
}
Reverse engineering suggests that the hidden attribute names generated by
__event is of format:
__eventHandlerList_<ClassName>_<EventMethod>
Example below should work if I understand the Microsoft documentation
correctly.
Hopfelly there is some compiler upgrade that fixes this bug?
[event_source(native)]
class CTubeDev {
....
__event void OnEnableControls(const BOOL abEnable);
....
};
[event_receiver(native)]
class CPowerDlg : public CDialog {
....
void DoEnableControls(const BOOL abEnable);
....
}
Somewhere in CPowerDlg I call the hook function only once:
__hook(&CTubeDev::OnEnableControls,m_pDev, &CPowerDlg:oEnableControls);
I take care that the __hook is only called once and no __unhook is called
before a __hook.
So when I call OnEnableControls() from a CTubeDev instance, then the
DoEnableControls() is correctly called, processed but when returning back to
the CTubeDev instance I get an access violation.
Reverse engeneering suggests that there is a node->next pointer that is not
initialized to NULL in the events list handler when the class is created.
A very dirty fix so far to make this system work as it should, is to try to
find the hidden generated attribute created by the __event keyword, and
initialize this to NULL in the constructor, like this.
//--------------------------------------------------------------------
CTubeDev::CTubeDev()
{
__eventHandlerList_CTubeDev_OnEnableControls=NULL;
.....
}
Reverse engineering suggests that the hidden attribute names generated by
__event is of format:
__eventHandlerList_<ClassName>_<EventMethod>