PRB: Marshaling Support for VT_DISPATCH Not Compatible (326202)



The information in this article applies to:

  • Microsoft Visual J++ 6.0
  • Microsoft Visual J# .NET (2002)
  • Microsoft Visual J# .NET (2003)

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 "More Information" 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, "showMe");
			// late-bound call on dispatch interface
		}
	}
}
				
For more information about COM interop marshaling, visit the following Microsoft Web site:

REFERENCES

For more information about Java-language support in .NET, visit the following Microsoft Web site:

Java Language Support for .NET
http://msdn.microsoft.com/vjsharp/


Modification Type:MajorLast Reviewed:8/7/2003
Keywords:kbMarshal kbprb KB326202