470,648 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

BUG: __raise throws access violation if __unhook called from inside event handler (native events)

I need to unhook event receiver as result of native C++ event.
It unhooks successfully, but __raise does not return and throws access
violation.

Visual Studio 2003

How to reproduce:

Consol Win32 exe project

#include "stdafx.h"

[event_source(native)]
class Publisher
{
public:
__event void Signal(Publisher* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}

};

[event_receiver(native)]
class Subscriber
{
public:

void Handler(Publisher* sender)
{
// unhooks successfully
Unhook(sender);
return;
}

void Hook(Publisher* sender)
{
__hook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}

void Unhook(Publisher* sender)
{
__unhook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
};

int _tmain(int argc, _TCHAR* argv[])
{
Publisher pub;
Subscriber sub;

sub.Hook(&pub);
pub.RaiseSignal();
return 0;
}

Debug output window

'Hook.exe': Loaded 'C:\Projects\Hook\Debug\Hook.exe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', Symbols loaded.
First-chance exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
Unhandled exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
Nov 17 '05 #1
2 2683
"Boris Fortes" <fb****@yahoo.com> wrote in message
news:10**************************@posting.google.c om...
I need to unhook event receiver as result of native C++ event.
It unhooks successfully, but __raise does not return and throws access
violation.


See if this helps: KB Article KB811193 "BUG: Access Violation Exception
When a Native Event is Fired or Unhooked"
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Nov 17 '05 #2
M.C
Hi,

Calling __unhook in a handler should cause a race condition, but because the
injected critical section code does nothing (???), so your code get pass but
a GPF happened because the call was between walking functor node.

You can check this with /Fx switch.

"Boris Fortes" wrote:
I need to unhook event receiver as result of native C++ event.
It unhooks successfully, but __raise does not return and throws access
violation.

Visual Studio 2003

How to reproduce:

Consol Win32 exe project

#include "stdafx.h"

[event_source(native)]
class Publisher
{
public:
__event void Signal(Publisher* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}

};

[event_receiver(native)]
class Subscriber
{
public:

void Handler(Publisher* sender)
{
// unhooks successfully
Unhook(sender);
return;
}

void Hook(Publisher* sender)
{
__hook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}

void Unhook(Publisher* sender)
{
__unhook(&Publisher::Signal, sender, &Subscriber::Handler, this);
return;
}
};

int _tmain(int argc, _TCHAR* argv[])
{
Publisher pub;
Subscriber sub;

sub.Hook(&pub);
pub.RaiseSignal();
return 0;
}

Debug output window

'Hook.exe': Loaded 'C:\Projects\Hook\Debug\Hook.exe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\ntdll.dll', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYSTEM32\kernel32.dll', Symbols loaded.
First-chance exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.
Unhandled exception at 0x00411e51 in Hook.exe: 0xC0000005: Access
violation reading location 0xfeeefeee.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Rhy Mednick | last post: by
9 posts views Thread by Anders K. Jacobsen [DK] | last post: by
14 posts views Thread by Andy | last post: by
5 posts views Thread by =?Utf-8?B?VmFubmk=?= | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.