Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I have an environment where there are two different COM objects which implement IActiveScript interface and they get IDispatch as reference to the site where the scripts are placed.

Now, I want to refer to a function of one script from inside another Script(both Scripts are inside the Scripting Engine but loaded in different sites), is it possible ? How will it work and How to implement it?

Thanks
Posted
Updated 9-Jul-12 4:20am
v2

1 solution

If you want to create VBScript COM Object, you have read about Active Script Components. You will have to create an XML document with special format and extension and register it with regsvr32.
 
Share this answer
 
Comments
Techiz 9-Jul-12 10:22am    
Thanks for the Reply, I actually have studied that and implemented it. I have updated the question Kindly help me in that. Thanks
armagedescu 9-Jul-12 11:19am    
Ok.
Suppose, you have ApplicationX which is using (hosting) two scripts, VBScript1 and VBScript2.
So far everything is good. ApplicationX has the script dispatch do script1 and script dispatch to script2, let's call them Script1IDispatch and Script2IDispatch.
VBScript1 can not call functions from VBScript2. But VBScript1 can call functions from ApplicationX and VBScript2 also can call functions from ApplicationX. And viceversa, ApplicationX can call functions from VBScript1 and from VBScript2.
Any VBScript object is just an IDispatch. So, you need to initialize a script object inside the VBScript2. Supposing you have the variable SomeVBScript2Variable, which is meant to refer VBScript1. All you have to remember, is that any objects are just IDispatch. In this case, you initialize a VBScript2 variable to Script1IDispatch.
In pseudocode it would look like this:
Script2IDispatch->SomeVBScript2Variable = Script1IDispatch.
In real code this means to call GetIDsOfNames for "SomeVBScript2Variable" and to call Invoke with a pointer to Script1IDispatch.
After that you can call from VBScript2 SomeVBScript2Variable.SomeScript2Method...
armagedescu 9-Jul-12 11:23am    
You also can do it the way round. From VBScript2 call some ApplicationX function meant to get the Script1IDispatch. All you have to know, is that an IDispatch from VBScript point of view is an object, with functions, methods, properties, nothing more.
Techiz 10-Jul-12 1:25am    
For the Approach, you have discussed is kind of implementing Automation Wrappers over Scripting Sites. Is there any way that we can put Global Functions in VB-Scripting Engine. So that It can be accessible from any Scripting Site without introducing any Automation wrappers over scripting sites.
armagedescu 10-Jul-12 2:00am    
As I already told in the first reply, you have to write script components. They are not wrappers, they are components. Read about script components. This is the only way to extend the scripts. For instance VBScript regular expression is plain ActiveX, and you may use it outside the script anywhere you like.
They are XML files, with .wsc extensions. Inside that files you put your code. After that register extension with regsvr32 and it will be accessible from any application, script, C++, VBA, JScript, C#. You instantiate them as COM objects, with CreateObject inside VBS, CoCreateInstance in C++, new ActiveXObject in jscript and so on. You can write ActiveX components components in any language you like.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900