PRB: Firing Event in Second Thread Causes IPF or GPF (196026)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q196026 SYMPTOMS In Visual Basic, an event fired by an ActiveX component
from a thread other than the main thread will sometimes cause an Invalid Page
Fault (IPF) or General Protection Fault (GPF). Usually it seems to work fine in
the Visual Basic IDE but fails when it runs as a standalone EXE. CAUSE Visual Basic uses an apartment threading model.
Cross-thread function calls need to be marshalled. Visual Basic does not
support events fired directly from any thread other than the main thread
created by a Visual Basic project without marshalling. RESOLUTIONMethod 1 Marshall the event firing code:
- The thread being spun off needs to call
CoInitialize/CoUnInitialize.
- The sink interface being called back on in the thread must
be marshalled over to that thread with
CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream.
Method 2 Instead of firing an event from a secondary thread, post a
message back to the main thread and fire the event there. An example of this
method is given later in this article. STATUS This behavior is by design. REFERENCES For additional information about firing an event
from a second thread and about the PostMessage method, click the following
article numbers to view the articles in the Microsoft Knowledge Base: 157437
FILE: Fireev.exe Fires Events from a Second Thread
280512 SAMPLE: ATLCPImplMT Encapsulates ATL Event Firing Across COM
Modification Type: | Major | Last Reviewed: | 5/22/2003 |
---|
Keywords: | kbActivexEvents kbcode kbprb kbThread KB196026 |
---|
|