Article ID: 260280 - View products that this article applies to.
This article was previously published under Q260280
A java.lang.ClassCastException is generated when you use a COM object obtained from a com.ms.com.Variant.toObject() or Variant.toDispatch(). Specifically, the Variant, generated through Variant.clone() or Variant.cloneIndirect(), contains a reference to a COM proxy (COM interface pointer marshaled to another thread).
The Microsoft virtual machine's implementation of Variant.clone() and Variant.cloneIndirect() invokes the Win32 VariantCopy and VariantCopyInd functions, respectively, on the caller's thread instead of the Variant's home thread. If the underlying object stored in the Variant is a COM proxy, an attempt to perform a QueryInterface to the COM interface causes a COM error, which is represented as a java.lang.ClassCastException in Java.
An example that demonstrates this problem is included in the "More Information" section.
A workaround for this problem is to use ComLib.executeOnContext() to call Variant.clone() or Variant.cloneIndirect() on the Variant's home thread by passing the target Variant as the first parameter to ComLib.executeOnContext().
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This problem was corrected in Windows 2000 Service Pack 1.
Steps to Reproduce BehaviorThis code causes the java.lang.ClassCastException that is described in the "Symptoms" section:
For additional information about the latest service pack for Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:
260910For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
(http://support.microsoft.com/kb/260910/EN-US/ )How to Obtain the Latest Windows 2000 Service Pack
Article ID: 260280 - Last Review: June 14, 2006 - Revision: 2.0
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Contact us for more help