| > WScript needs the typelib to do that.
|
| Are you sure ? The VBS engine itself does not need it ...
|
Interesting issue.
The following line does a great deal of work to load
the library and work out the available functions:
Set FSO = CreateObject("Scripting.FileSystemObject")
WScript then looks up Scripting.FileSystemObject,
which turns out to have a CLSID of:
{0D43FE01-F093-11CF-8940-00A0C9054228}
Looking under that key there's a Typelib key
with this default value:
{420B2830-E718-11CF-893D-00A0C9054228}
Tracking that CLSID to HKCR\Typelib\
turns up this:
HKEY_CLASSES_ROOT\TypeLib\{420B2830-E718-11CF-893D-00A0C9054228}\1.0\0\win32
The default value in that key is the path to
scrrun.dll, which is where the typelib is in this
case. If you change that path to something
invalid, instantiating FSO will fail.
I don't entirely understand the whole thing. As I
understand it, there's no reason that WScript can't
call GetIDsOfNames and Invoke from a COM library
with a Dispatch interface (the only kind VBS can use)
and just wing it, assuming your script is making
valid calls. But it doesn't do that. It looks up the
typelib to map the interfaces and fails if it can't
do that. Maybe the other way would just be too
messy. With typelibs, WScript can oversee whether
you make valid calls. Without it, if you call FSO.FileExxists
then WScript would have to depend of scrrun.dll to
provide smooth error handling. A few typos could
potentially result in a few crashed DLLs.
| > It's possible to load an unregistered server through
| > compiled code.
|
| True. I've wrapped the VBS engine in a program of mine, and had no
| problem with adding a function which could load objects and make them
| available to the script.
I don't mean wrapping wscript. I mean directly loading
a DLL through C++ code, with no need for that DLL to
be registered. I don't understand the details
myself. C++ mixed with COM is a very messy business.
It seems to involve loading an Ax DLL with LoadLibrary
and/or CoCreateInstance. I'm not sure, in that case,
whether a typelib is still required or whether the
loading process could just use Dispatch functions to
map function addresses.
There was a humorous posting by Raymond Chen some
years ago. I came across it once when I was trying to
understand Windows shell functions in VB. He wrote C++
code to find the focused item in an Explorer window:
https://blogs.msdn.microsoft.com/oldnewthing/20040720-00/?p=38393
It's a very complicated mess. Something that VBS
can do in a few simple lines. COM is designed to make
things easy and object-oriented, but the mechanics
behind it are complicated.
| > I use a small tool in VB6, directCOM.dll, to load my own
| > Ax DLLs without reg.
|
| Something I was also thinking about, a small object that would function as
a
| boostrap-loader. I'd rather not though (not all computers allow a user
to
| install ActiveX components -- for a good reason).
|
That's the point of DirectCOM. It loads Ax without
any registration. It may be that the Ax must have an
internal typelib, and/or it may be that the Ax can only
be used through a Dispatch interface. But that
wouldn't matter for VBS. What you want is exactly
why I use DirectCOM: I have an Ax DLL in an a program
that gets installed and I wanted to avoid registration
issues. Especially with later Windows versions, it's
cleaner if I can load a COM object from my own program
folder without needing to register it.
--------- DirectCOM ----------------
In case this might be of use to you:
The link here contains directCOM.dll:
http://www.thecommon.net/
Version 3 has it. Version 4 might. But at least one
of the downloads does. The rest of the download is
not of much use. Olaf has created a very impressive
and extensive set of libraries that are free to use,
but the design of them is unorthodox and docs are
non-existent.
Usage in VB6:
Private Declare Function GETINSTANCE Lib "DirectCOM.dll" (FName As String,
ClassName As String) As Object
Private Cls1 as Server1.Class1 ' example: Scripting.FileSystemObject
Set Cls1 = GETINSTANCE(App.Path & "\yourlib.dll", "Class1")
DirectCOM instantiates the class and hands it off. One
need only set the object to Nothing to release it. I guess
that theoretically something like DirectCOM could provide
a commandline option that VBS could use, but as far as
I know there's no such thing available.
And of course you'd need to be careful with this method.
DirectCOM is getting the Dispatch interface and handing
it off. From there it's up to you and the Ax DLL how well
you get along. :)