Microsoft KB Archive/214409

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

Article ID: 214409

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Java Virtual Machine

-



This article was previously published under Q214409



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:
 * Method 1: Use CreateObject method in Visual Basic to use the DLL (late binding).
 * Method 2: Treat the method as a property (early binding).
 * Method 3: Edit the .tlb to correct the typo and rebuild it (early binding). The details of this workaround are beyond the scope of this article.

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. 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.

