Answered by:
COM dll created in VB 2019 works with VB6 but not with VBScript

Question
-
Hi everyone!
As a visually impaired programmer mainly I develop scripts for screen reader programs (JAWS & NVDA) to make easier to use other Windows programs & apps with these screen readers. Currently I'm developing scripts for JAWS. Its script language (which is derived from Basic) can accept COM objects as "functionality extender". Until recently I developed my "extenders" in VB6 as ActiveX dll's. They worked correctly with JAWS. But now I decided to "upgrade" to .NET and tried to make my first com visible interop class in Visual Basic 2019 with the Visual Studio Community 2019. I have read every MS walktroughs and other available sources on the net before I began to write my code.
After compiling to a release version I tried It with JAWS but did not work. I got the error message, that ActiveX component can't create the object.
Because VB6 was installed on my machine I thought I took a try with it, too and I wrote a small test program, which is worked correctly. My interop COM object was created and the simple test message was displayed. Finally I decided to write the same test program in VBScript,, too, what did not work, like in JAWS. I got the same error message. (Generaly COM objects working with VBScript works also with JAWS.)
I use a 64-bit machine with Windows 10 1709.
What could be the problem? Why works with VB6 and why not with JAWS & VBScript?
My code:
(My COM dll)
• IComClassInterface.vb file
Public Interface _ITester2
Sub TestMessage()
End Interface ' _ITester2
• ComClass.vb file:
Imports System
Imports System.Runtime.InteropServices
<ComClass(Tester2.ClassId, Tester2.InterfaceId, Tester2.EventsId)>
Public Class Tester2
Implements _ITester2
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "3d640e73-5ea4-4b49-a7ca-42886925d2b5"
Public Const InterfaceId As String = "04aa4001-e8b9-4dcf-86a8-77c7e101245f"
Public Const EventsId As String = "e2f8a2e0-c42e-469f-8a55-bf853ff7ca2b"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub ' New
Public Sub TestMessage() Implements _ITester2.TestMessage
MsgBox("This is a test message from the COM object.")
End Sub ' TestMessage
End Class ' Tester2
Test code (in VB6) what worked:
Option Explicit
Sub Main()
Dim oTest As COMClassTest2.Tester2
Set oTest = New COMClassTest2.Tester2
oTest.TestMessage
Set oTest = Nothing
MsgBox ("Ez a vége.")
End Sub
• Test code in VBScript (hwat not worked)
Option Explicit
Dim oTest
Set oTest = CreateObject("COMClassTest2.Tester2")
oTest.TestMessage
Shepherd Godson -------------------------------------------------------- A simple blind developer mastering development of accessible applications for his soulmates
- Moved by Julie Xu-MSFTMicrosoft contingent staff Monday, February 3, 2020 4:08 AM VBS
Sunday, February 2, 2020 3:44 PM
Answers
-
Make sure that the bitness of the scripting host and the VB COM server are the same.
So, assuming you are running a 64 bit version of the scripting host then your COM server should be a 64 bit binary. Use the project properties to specify a 64 bit dll instead of AnyCPU.
And, most importantly, register the COM server with the 64 bit version of regasm.exe
- Edited by RLWA32 Tuesday, February 4, 2020 11:56 AM
- Marked as answer by Csaba Árpádházy-Godó Tuesday, February 4, 2020 5:09 PM
Tuesday, February 4, 2020 10:54 AM
All replies
-
Hello,
My recommendation is to contact the vendor and ask if VB.NET is supported as from my quick review of the site there is nothing listed except scripting.
Vendor site https://www.freedomscientific.com/
Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
NuGet BaseConnectionLibrary for database connections.
Sunday, February 2, 2020 5:08 PM -
Karen, thank you for your answer. Believe me, I contacted already with Freedom. They said, every COM objects VBScript can "consume" should work with JAWS Script, too. (BTW I wrote a huge JAWS Script function library to wrap Windows Scripting Host objects and functions, like RegExp or FileSystem objects. They work fine.)
I have read in many articles that the autors wrote .NET COM libraries to use with VBScript. I tried every posted sample in the theme, but I got every time the same error message in VBScript: AtctiveX component can't create the object. The bad thing in connection with the mentioned articles, that none of them contained the VB project as downloadable package to run on my machine and try them directly.
The ActiveX dll's written in VB6 works very well with JAWS, and now I can encapsulate .NET functionality into .NET type COM libraries, than I can attach them to a VB6 dll wrapper to use them in JAWS, bhut I'd like to avoid this "Dual-wrapping".Shepherd Godson -------------------------------------------------------- A simple blind developer mastering development of accessible applications for his soulmates
Sunday, February 2, 2020 6:10 PM -
I tucked away this sample a long time ago. I hope you find it helpful VBDLLComServer.zipSunday, February 2, 2020 6:42 PM
-
Thank you very much for this sample project. I compiled it with strong key, in VS 2008 version, (because VS 2019 cried because of some code incompatibility) and registered it successfully with the old regsrv app (with codebase switch), but running the attached VBScript file I got the same error message as previously: The ActiveX component can't create the object ’VBDllCOMServer.SimpleObject . Code: 800A01AD
Next step will be tomorrow morning, that I will try it to register on an other machine to see if runs it there or not.Shepherd Godson -------------------------------------------------------- A simple blind developer mastering development of accessible applications for his soulmates
Tuesday, February 4, 2020 3:12 AM -
Make sure that you generate and register a type library for the server.Tuesday, February 4, 2020 3:26 AM
-
I did try to register and run your compiled sample on other machines, too. Unfortunately the result was same. I have got the stupid error message, that ActiveX component can't create the object.
I registered the dll with /codebase switch and used also the /tlb switch, to generate and register the typelib for the object.
What interesting is, that if I copy the code into a VBA client (Excel) and let run, than it works correctly. Without any error. As far as I know VBA and VBS are very close relatives, so I assume if VBA can "consume" the object, also VBS should be, shouldn't be?
I also tried to find some solution or some pieces of advice in connection with the displayed error code, but nothing helpful found. Most ot the articles assumes that the registration of the object is incorrect or the object is not registered. But I did check the Registry and the object is correctly registered. (I think, if there is an error, than also VBA could not create it.)
I'm sad because I see that Visual STUDIO, which is accessible, can't solve this simple problem. Delphi is capable of generating native code, and ActiveX dlls created with it work well with VBScript, but the IDE is not accessible! That is, it is almost useless blindly.
So what could be the solution? Why works the code with VBA and doesn't with VB Script?Shepherd Godson -------------------------------------------------------- A simple blind developer mastering development of accessible applications for his soulmates
Tuesday, February 4, 2020 9:53 AM -
Make sure that the bitness of the scripting host and the VB COM server are the same.
So, assuming you are running a 64 bit version of the scripting host then your COM server should be a 64 bit binary. Use the project properties to specify a 64 bit dll instead of AnyCPU.
And, most importantly, register the COM server with the 64 bit version of regasm.exe
- Edited by RLWA32 Tuesday, February 4, 2020 11:56 AM
- Marked as answer by Csaba Árpádházy-Godó Tuesday, February 4, 2020 5:09 PM
Tuesday, February 4, 2020 10:54 AM -
Thanks! It solved the problem. It was my mistake, that I did not pay attention to the bitness. It solved the problem, and also my original works are working correctly when I register they correctly And not only with VBS, but also with JAWS Script.
Shepherd Godson -------------------------------------------------------- A simple blind developer mastering development of accessible applications for his soulmates
Tuesday, February 4, 2020 5:12 PM