PRB: Access Violation Using CDO in Multi-threaded COM Server
ID: Q236577
|
The information in this article applies to:
-
Collaboration Data Objects (CDO), version 1.21
SYMPTOMS
When using CDO in a multi-threaded COM server, an access violation may occur on releasing the last object hosted by the server.
CAUSE
CDO uses messaging application programming interface (MAPI), and the first thread that uses MAPI in a process causes certain initialization actions to occur. These particular initialization actions do not reoccur when other threads use MAPI. When the original thread terminates, specific de-initialization actions happen within the server process, which may lead to problems with the other threads using MAPI.
For example, the following scenario illustrates how an access violation can occur:
A Microsoft Visual Basic 6.0 ActiveX EXE server has a class that creates a CDO session in its initialize event and releases it in its terminate event. A client application creates an instance (A) of this class and then a second instance (B). The client releases instance A and then releases instance B. This leads to the de-initialization of MAPI and the shutdown of the server process. During these activities an access violation occurs.
RESOLUTION
There are at least three ways in which you can avoid this problem:
- Take the creation/destruction of the CDO object out of the class initialize/terminate. Give the class a method which the client calls explicitly to initialize the CDO session and a corresponding method that releases the CDO session.
- Have the class create a dummy object provided by a DLL with a COM threading model of "single" that creates a CDO session before the main class initializes its own CDO session. This forces MAPI to be initialized first on the primary single threaded apartment (STA) of the process rather than on one of the secondary STAs.
- Release the objects in the reverse order in which they were created.
Additional query words:
crash error fault GPF IPF
Keywords : kbCDO121 kbMsg kbGrpMsg kbDSupport
Version : WINDOWS:1.21
Platform : WINDOWS
Issue type : kbprb