js4vb vtComObj


Author: Dave
Date: 12.26.25 - 9:01am



So in the js4vb js engine, everything is held as a CValue class instance with different types. Its like the script engine version of a variant. This includes numbers, strings, js functions, js objects, and COM object holders.

different types can have properties assigned to them. Like a JS object can have fields of other types including functions.

So normal convention would be that COM object types, forward all of their calls to the COM subsystem and do not have any JS properties or functions associated with them. But! thats just a convention, not an actual design requirement. In fact! with very few tweaks of the assumptions of the engine, we can start attaching js functions and properties to a COM object!

This sounds crazy like adding functions to a vtable and extending a binary COM object is usually a dark art..but in our scenario, its actually just a parlor trick!

This also allows us to override COM methods in JS, because we control the calling engine. Simply look for JS methods by name first, effectivly an override without changing the ground truth of the binary COM object.

And if you want to still be able to call the original COM method thats overridden? Simple convention actually. Add an underscore to the method name. The COM call engine will see the underscore. If a JS method override exists with the base name, then we just strip the underscore and call the COM version not the JS version.

Its actually super simple and took very little code to implement all of this!

You see, there is no spoon...

Adding COM helper methods can be done from the vb6 host side, or the JS side.

Controlling your own javascript engine is a very satisfying experience. heres the commit if your interested.

//vb6
intrep.AddCOMObject "form", Me
intrep.AttachCOMHelper "form", "taco", "function(cmd){print('its tuesday ' + cmd + '!');}"

//js
var wsh = new ActiveXObject("WScript.Shell");

// Add a JS helper that uses the actual COM method
wsh.safeExpandEnv = function(varName) {
    var result = this.ExpandEnvironmentStrings("%" + varName + "%");
    if (result === "%" + varName + "%") {
        return "(undefined)";  // Variable doesn't exist
    }
    return result;
};

console.log(wsh.safeExpandEnv("PATH"));  // Returns expanded path or "(undefined)"
form.taco('dude')

wsh.Run = function(cmd) {
    console.log("[LOG] " + cmd);
    return this._Run(cmd, 1, true);  // Calls original COM Run
};

wsh.Run("C:WindowsSysWOW64
otepad.exe")


In other news i started experimenting with sinking events for various controls just in case. Bad news through, we cant wire it up to intrisic vb form controls, only ocx and vb classes. Command buttons etc use vtables not idisp which we could hook but I wouldnt. A form engine with event handling would be pretty sweet to add to teh js engine!




Comments: (1)

On 01.17.26 - 4:32pm Dave wrote:
the reason i wanted this..in duk4vb COM was bolted on and I had to create JS proxy classes to represent COM objects.

it was painful, but it was super handy to be able to add custom js logic before or after a com call. Some things are best done on the JS side (like checking/modifying 64bit numbers).

When i switched to js4vb, I came to miss this capability. Now we have the best of both worlds.

Also now that some COM methods are returning native JS objects (like bigint or json). It becomes super bulky to use the vb api in vb as its now meant for js consumption!

nerd problems..pfft

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 79 + 47 = ? followed by the letter: K 



About Me
More Blogs
Main Site
Posts: (All)
2026 ( 1 )
2025 (6)
     js4vb vtComObj
     Vb6 CallByNameEx
     js4vb
     COM dynamic proxy
     go get lost
     Courier Regular Win11 Missing
2024 (3)
     VB6 JSON
     ffmpeg voodoo
     RegJump Vb
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 ( 6 )
2017 ( 6 )
2016 ( 22 )
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )