Serious bug discovered in VC .NET (2002) compiler. [event_source(native)] and __event methods

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::DoEnableControls);

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

Guest

I want to add that I do not use managed code, and I link with the multi
threaded static libraries.
And this too might help:
Compiler directives :

/GA /I "..\..\base" /D "_MBCS" /FD /EHsc /RTC1 /MTd /Zp16 /GS /Gy
/Fp".\Debug/TubeDev.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3
/nologo /c /Wp64 /Zi /TP
 

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