Advanced MSScript Control

Author: Dave
Date: 12.19.10 - 4:43am

So i am playing with the MSScript control trying to hack in support for some stuff in PDFStreamDumper and I am hitting some weird bugs.

Some I have figured out, some I have almost figured out. and some are kicking my ass :(

Here is the Javascript I need to support:


First you have to have an app.doc object. Ok that was easy.
Public app as object
public doc as object

Private Sub Class_Initialize()
    Set app = Me
    Set doc = Me
Then you create a getAnnots(arg) method. now {nPage:0} is a hash array. How do you access that in VB6? The TypeName(arg) turns out to be JScriptTypeInfo which didnt help at all. Turns out in my getAnnots(arg) function, you can access the nPage variable value by just asking for arg.nPage. Ok so that turned out to be easy too. (not intutive but easy)

So JScriptTypeInfo is the JS object you can make late bound calls to.

So now whatever we return from getAnnots() has to be able to be accessed in Javascript array notation, and each element has to be an object.

One would think you could just:
dim x()
set x(0) = me
getAnnots = x()
But this doesnt work. Not as a variant array, not as an object array. If you return a collection, it kind of works, but then your parent javascript would have to be written like:


Note the () method call instead of [] array object index. Doesnt jive if trying to keep existing JS working.

I even went to the hackerific test of:

getAnnots ="getJSArray(1,2,3)")

Where getJSArray is a function in the script control that explicitly returns a JS array. but..(and give me a big WTF here) my JS array is somehow automagically converted to a comma delimited string when it makes it back to VB6..

So i dont know how to return any kind of array from vb6 code run through the MSScript control to a Javascript function that called it. grrrr...

I may have to do the majority of the code in JS, and only call out to the VB6 methods to grab data. So build the structure in JS, data from VB. this works below: (where tb. is a VB6 form object with an alert method)
function AnnotClass(x){
   this.subject = "my Annot " + x

function getAnnot(x){
   var ret = new Array()
     ret[i] = new AnnotClass(i);
   return ret

tb.alert( getAnnot({nPage:22})[1].subject ) the above is now working. JS to build the function and array structure, and calling back into VB from the JS class to get the data.

Which brings us to our next bug. If you use the this keyword in a script in a script automatically refers to the first object you added with AddObject and you can not override it. grrr #2

Update: Actually there may be a way to trick it though..I dont know if I dare use this on complex scripts..but for simple scripts..I noticed that JS classes can use the this keyword and it does work. The difference is not only are they in a function..but the function is being called as class instantation with the new keyword.
text1 = "vbclass.myAlertTypeName( this )"
sc.AddCode "function main(){" & Text1 & "}"
sc.eval "var x = new main()"
The above code shows the this pointer is now a JScriptTypeInfo object instead of the VB class it would normally do. However this appears to now exclusivly refer to properties of the new JS object. So this.unescape is empty...aghh but that reveals a step in the right direction. Since this.unescape is just a can also hold a function
text1 = "this.unescape = unescape; vbclass.myAlert( this )"
Now gives us the format we need.

Dont know if i can trust that if I have to add scripts with their own functions and nested functions..might be worth a try for compatiablity sake, but seems like it could cause some really hard bugs to track down.

JS engines are not the most reliable creatures

Comments: (0)

Leave Comment:
Email: (not shown)
Message: (Required)
Math Question: 64 + 90 = ? followed by the letter: D 

About Me
More Blogs
Main Site
Posts: (year)
2024 (2)
     ffmpeg voodoo
     RegJump Vb
2023 (9)
     VB6 Virtual Files
     File handles across dlls
     python abort / script timeout
     VB6 Python embed w/debugger
     python embedding
     VB6 IDE Enhancements
     No Sleep
     A2W no ATL
2022 (4)
     More VB6 - C data passing
     Vb6 Asm listing
     Byte Array C to VB6
     Planet Source Code DVDs
2021 (2)
     Obscure VB
     VB6 IDE SP6
2020 (4)
     BSTR from C Dll to VB
     Cpp Memory Manipulation
     ActiveX Binary Compatability
2019 (5)
     Console tricks
     FireFox temp dir
     OCX License
     Extract substring
     VB6 Console Apps
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
2016 (22)
     VB6 CDECL
     UDT Tricks pt2
     Remote Data Extraction
     Collection Extender
     VB6 FindResource
     DirList Single Click
     Reset CheckPoint VPN Policy
     VB6 BSTR Oddities Explained
     SafeArrays in C
     BSTR and Variant in C++
     Property let optional args
     Misc Libs
     Enum Named Pipes
     Vb6 Collection in C++
     VB6 Overloaded Methods
     VB6 Syncronous Socket
     Simple IPC
     VB6 Auto Resize Form Elements
     Mach3 Automation
     Exit For in While
2015 (15)
     C# self register ocx
     VB6 Class Method Pointers
     Duktape Debug Protocol
     QtScript 4 VB
     Vb6 Named Args
     vb6 Addin Part 2
     VB6 Addin vrs Toolbars
     OpenFile Dialog MultiSelect
     Duktape Example
     DukTape JS
     VB6 Unsigned
     .Net version
     TitleBar Height
     .NET again
     VB6 Self Register OCXs
2014 (25)
     Query Last 12 Mos
     Progid from Interface ID
     VB6 to C Array Examples
     Human Readable Variant Type
     ScriptBasic COM Integration
     CodeView Addin
     ScriptBasic - Part 2
     Script Env
     MSCOMCTL Win7 Error
     printf override
     History Combo
     Disable IE
     API Hooking in VB6
     Addin Hook Events
     FastBuild Addin
     VB6 MemoryWindow
     Link C Obj Files into VB6
     Vb6 Standard Dlls
     CStr for Pascal
     Lazarus Review
     asprintf for VS
     VB6 GlobalMultiUse
     Scintilla in VB6
     Dynamic Highlight
     WinVerifyTrust, CryptMsgGetParam VB6
2013 (4)
     MS GLEE Graphing
     printf for VB6
     C# App Config
     Tero DES C# Test
2012 (10)
     VC 2008 Bit Fields
     Speed trap
     C# Db Class Generator
     VB6 vrs .NET (again)
     FireFox Whois Extension
     git and vb6
     Code Additions
     Compiled date to string
     C# ListView Sorter
     VB6 Wish List
2011 (7)
     C# Process Injection
     CAPTCHA Bots
     C# PE Offset Calculator
     VB6 Async Download
     Show Desktop
     coding philosophy
     Code release
2010 (11)
     Dll Not Found in IDE
     Advanced MSScript Control
     random tip
     Clipart / Vector Art
     VB6 Callback from C#
     Binary data from VB6 to C#
     CSharp and MsScriptControl
     HexDumper functions
     Js Beautify From VB6 or C#
     vb6 FormPos
     Inline Asm w VB6
2009 (3)
     The .NET Fiasco
     One rub on computers
     Universal extractor