Microsoft KB Archive/326202

= PRB: Marshaling Support for VT_DISPATCH Not Compatible =

Article ID: 326202

Article Last Modified on 8/7/2003

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition

-



This article was previously published under Q326202



SYMPTOMS
Incoming Variants of type VT_DISPATCH should be marshaled as type com.ms.com.Variant.VariantDispatch to Visual J# .NET. However, they are marshaled as type com.ms.com.Variant.VariantObject, instead.



CAUSE
This behavior occurs because of a limitation in the COM marshaling layer of the common language runtime.



RESOLUTION
To avoid this behavior, follow these steps:
 * 1) Use the com.ms.com.Variant::getObject method to extract the Java callable wrapper (JCW) for the COM dispatch interface.
 * 2) Use the methods in the com.ms.com.ComLib class to test for support of the interface. (For a more detailed description, see the &quot;More Information&quot; section.)



STATUS
This behavior is by design.



MORE INFORMATION
On the common language runtime, the following COM types are all marshaled to managed code as System.Object:
 * IUnknown
 * IDispatch
 * Variant

Because of this limitation, the following behavior might occur if you use a COM object of type IATLSimpleServer: import atltestsever.*; import com.ms.com.*;

public class Class1 {   public static void main (String[] args) {       IATLSimpleServer s = new ATLSimpleServer; Variant v = s.getVariant; // VARIANT of type VT_DISPATCH returned from COM System.out.println(v.getvt == Variant.VariantDispatch); // true in Visual J++, false on the common language runtime System.out.println(v.getvt == Variant.VariantObject); // false in Visual J++, true on the common language runtime Object obj = v.getObject; if (ComLib.supportsInterface(obj, ComLib.IID_IDispatch)) {           Dispatch.call(obj, &quot;showMe&quot;); // late-bound call on dispatch interface }   } } For more information about COM interop marshaling, visit the following Microsoft Web site:

Marshaling Data with COM Interop

http://msdn.microsoft.com/library/default.asp?url=/library/en-us /cpguide/html/cpconmarshalingdatawithcominterop.asp

