Article ID: 133042
Article Last Modified on 11/21/2006
APPLIES TO
- Microsoft Foundation Class Library 4.2, when used with:
- Microsoft Visual C++ 2.0 Professional Edition
- Microsoft Visual C++ 4.0 Standard Edition
- Microsoft Visual C++ 4.1 Subscription
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
This article was previously published under Q133042
SUMMARY
In some cases, you may want an OLE Automation Local-Server to pass its
IDispatch pointer to another Local-Server through an automation method.
However, the pointer will become invalid after the method in the second
server returns, so an Access Violation will occur if the second server
tries to use the pointer later.
To maintain the integrity of the pointer, you need to call AddRef on the
IDispatch pointer within the second server, as described in the following
rule from the OLE SDK documentation:
If a local copy of an interface pointer is made from an existing global
interface pointer, the local copy must be independently reference-
counted. This separate reference count is necessary because the global
copy can be destroyed while the local copy is in use.
REFERENCES
- Visual C++ Books Online Contents\OLE 2.0 SDK\Chapter 6 Component
Object Interfaces and Functions \Iunknown Interface\Reference Counting
Rules.
- OLE 2 Programmers Reference, Volume 1, pages 191-195.
- Inside OLE 2, pages 83-90.
Keywords: kbautomation kbhowto kbserver KB133042