473,856 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(na tive)]
class Publisher
{
public:
__event void Signal(Publishe r* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}

};

[event_receiver( native)]
class Subscriber
{
public:

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

void Hook(Publisher* sender)
{
__hook(&Publish er::Signal, sender, &Subscriber::Ha ndler, this);
return;
}

void Unhook(Publishe r* sender)
{
__unhook(&Publi sher::Signal, sender, &Subscriber::Ha ndler, 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\Ho ok\Debug\Hook.e xe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYS TEM32\ntdll.dll ', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYS TEM32\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 2869
"Boris Fortes" <fb****@yahoo.c om> wrote in message
news:10******** *************** ***@posting.goo gle.com...
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(na tive)]
class Publisher
{
public:
__event void Signal(Publishe r* sender);
void RaiseSignal()
{
// throws access violation
__raise Signal(this);
}

};

[event_receiver( native)]
class Subscriber
{
public:

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

void Hook(Publisher* sender)
{
__hook(&Publish er::Signal, sender, &Subscriber::Ha ndler, this);
return;
}

void Unhook(Publishe r* sender)
{
__unhook(&Publi sher::Signal, sender, &Subscriber::Ha ndler, 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\Ho ok\Debug\Hook.e xe', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYS TEM32\ntdll.dll ', Symbols loaded.
'Hook.exe': Loaded 'C:\WINDOWS\SYS TEM32\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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5230
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote peer. I have no problem connecting the peers and streaming Network Streams. When the incoming data is finished recieving, I act upon it. This works great as long as all of the code is inside my form. I want to build the networking code into a...
15
2103
by: Rhy Mednick | last post by:
I have a class (let's call it ClassA) that I've written which has events. In another class (let's call it ClassB) I create a collection of ClassA objects. In a third class (ClassC) I create a reference to some of the ClassA objects created in ClassB. In ClassC I hook into the ClassA events with a foreach loop so that I hook each object. The code is something like this: class ClassC { void SomeMethod() { foreach (ClassA item in...
1
1300
by: | last post by:
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? class CTubeDev {
9
2458
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
14
3180
by: Andy | last post by:
Hi to All, I found the following issue, is this a bug? Create a new project and, in the main form, add a listbox with a few sample items. In the DoubleClick event of the listbox, add: Me.Dispose() Then run the project, double click on an item in the listbox to close the
7
3447
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the eventing code is slightly hidden. when you use events in Vb.Net you type this: <code> Public event MyEvent() </code>
5
2832
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no other thread will modify the list while operations are running. However, I at the end of the critical section, I need to fire an OnChange type of event, publishing the changed list item as part of my custom EventArgs. I want to be certain that...
3
9506
Frinavale
by: Frinavale | last post by:
Background An Event is a message sent out by an object to notify other objects that an action/trigger/state-change (ie. an event) has taken place. Therefore, you should use an event when an object's state change requires other objects to change as well. The object that sends an event is known as the event sender. The object that receives (or listens for) the event is known as the event receiver. Events implement the "Observer Design...
5
1900
by: Andy B | last post by:
I am trying to figure out how to make an object instance available for all methods of a class. I tried to do something like this: public class test { TheObject Instance = new TheObject(); TheObject.Dictionary<string, string= new Dictionary<string, string>(); .... } The first line (TheObject instance = new TheObject();) doesn't get
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11049
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10772
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9527
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7086
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4169
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.