FIX: VJ6 COM DLL: Function/Interface Marked Restricted or Automation Type Not Supported in VB (214409)
The information in this article applies to:
- Microsoft Visual J++ 6.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft 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 getSomething. 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 support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 6/14/2006 |
---|
Keywords: | kbBug kbfix kbVJ600fix KB214409 |
---|
|