FIX: VJ6 COM DLL: Function/Interface Marked Restricted or Automation Type Not Supported in VB

ID: Q214409


The information in this article applies to:


SYMPTOMS

The following error occurs when you try to use a Java COM DLL in Visual Basic (using early binding):

Compile error :

Function or interface marked as restricted,
or the function uses an Automation type not supported in Visual Basic


CAUSE

Invalid method prototypes are generated in the DLLs type library (*.tlb). The return type "VARIANT" is mistakenly listed as "VARIANT *". Visual Basic uses the .tlb to resolve parameter and return types at compile time.


RESOLUTION

This problem has been fixed in the Microsoft virtual machine versions 3158 and higher.

To fix the problem for older versions of the Microsoft virtual machine, do one of the following:

Java COM DLL Source Code


import com.ms.com.*;

/** compiled to 'Project2.dll'
 * @com.register ( clsid=151A5839-A724-11D2-B1B9-00C04FC22764, typelib=151A583A-A724-11D2-B1B9-00C04FC22764 )
 */ 

public class MyCOMClass {
	private Variant m_variant = new Variant("Merry Christmas");

	public void MyCOMClass( ) {
	}

	public Variant getPhrase( ) {
		return m_variant;
	}
} 

METHOD 1: Late Binding


Private Sub Command1_Click()
   Dim vj As Object
   Set vj = CreateObject("Project2.MyCOMClass")
   Text1.Text = vj.getPhrase
End Sub 

METHOD 2: Early Binding Using Properties


Public vj As New Project2.MyCOMClass

Private Sub Command1_Click()
    Text1.Text = vj.phrase
End Sub 

METHOD 3: Edit .tlb

You can extract the IDL from the .tlb, edit it so that "VARIANT*" return types are "VARIANT", and then regenerate the .tlb using the new IDL and the MIDL tool from Visual C++. Please see Visual C++ docs for information about how to use MIDL.


STATUS

This problem has been fixed in the Microsoft virtual machine versions 3158 and higher.


MORE INFORMATION

Method 1 works because you bypass the .tlb when you connect to the DLL at run time.

Method 2 works because you named the COM DLLs public method get<Something>. When a name that starts with "get", the balance of the method name is used as a property for the object. In this case, the method getPhrase is added to the .tlb twice: once as "VARIANT *getPhrase()" and again as "VARIANT phrase()".

Method 3 works because you are actually correcting the typo by hand.


REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/

http://support.microsoft.com/support/java/


© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Joseph B. Hall, Microsoft Corporation

Additional query words: Function interface marked restricted Automation Type Not Supported IDL TLB early late binding


Keywords          : kbCOMt kbJavaVM kbVBp600 kbVJ600bug kbVJ600fix kbGrpJava 
Version           : WINDOWS:6.0
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: July 28, 1999