BUG: You receive a "0xC0000005" error code when a native event is fired or unhooked (811193)
The information in this article applies to:
- Microsoft Visual C++ .NET (2002)
SYMPTOMSWhen you fire the __raise event, or you unhook ( __unhook) native events, in an unmanaged application, you may receive the
following error message: Unhandled exception at
virtual address in
executable: 0xC0000005: Access violation reading
location virtual address where
virtual address and
executable are values that are specific to your
application. CAUSEThe problem occurs when the constructor of the event source
is defined outside the class scope. The event handler list is not initialized
in the constructor of the event source in the injected code. Therefore, the
access violation occurs when the uninitialized memory is accessed.
WORKAROUNDTo work around this problem, use one of the following
methods: Method 1Define the constructor of the event source in its class scope. To
do this, replace the existing code: struct A {
__event void Event();
A();
void bar(){}
};
//Constructor defined outside class scope.
A::A() { } with the following code: struct A {
__event void Event();
A() { }; //Contructor defined in class scope.
void bar(){}
}; Method 2Include the eventHandlerList initialization code in the event source constructor. This assumes
that the .cpp file that contains the event source class definition is
event.cpp. The injected code that is generated by the compiler can be stored in
an intermediate file with help of the /Fx command line compiler option.
- At the command prompt, type the following command:
cl /Fx event.cpp The injected code that is generated by the compiler is saved in a file
with the .mrg.cpp extension. For event.cpp, the file with the injected code is
event.mrg.cpp. - In the intermediate file that is generated (event.mrg.cpp),
add the following code to the event source constructor:
Where A is the event source class, X is the namespace for A, and Event is the event identified by the __event keyword in the event source class.
- Compile the intermediate file at the command prompt with
the following command:
cl event.mrg.cpp
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
REFERENCESFor additional information about native event handling
keywords and attributes, see the following MSDN Web site:
Modification Type: | Minor | Last Reviewed: | 1/18/2006 |
---|
Keywords: | kbCompiler kberrmsg kbBug KB811193 kbAudDeveloper kbAudITPRO |
---|
|