Dissecting Vissim COM Internal from Inside Out (1)
This post has already been read 2757 times!
There was an interesting discussion at PTV Vissim LinkedIn group – how to access Vissim COM interface inside a DLL, e.g., a Signal Control DLL, an External Driver DLL etc. To properly answer this question, some in-depth understanding of the COM technology, C++ compiler internals, and Vissim binary level details are in order.
To begin with, Component Object Model (COM) is just a binary-level coding standard for out-of-process and in-process communication. It’s been out there for many years but somehow never become popular due to its daunting learning-curve for ordinary programmers, and then Microsoft began promoting .NET, which is essentially similar idea revamped at the level of Common Language Run-time (CLR) and Intermediate Language (IL).
In the nostalgia good-old days, COM/C++ programming required too steep learning curve to weed out sub-par programmers. Nowadays programming is so much easier with various .NET languages or scripting languages that do not require low-level knowledge of hardware or compiler internals. The barrier to programing is quite low nowadays; anyone with common sense can pick up programming, develop some apps, and sell such on streets.
In the context of Vissim, PTV wraps up the simulation elements and workflow into various interfaces. These interfaces are implemented (in C++) at binary level thus any language that supports COM (by their respective compilers) will be able to use Vissim’s COM interface to interact with Vissim functionality.
In the earlier days of Vissim, its COM interfaces allow a client application to invoke Vissim as an automation server (as an out-of-process use case). Then PTV added In-Menu scripting, that supports invoking COM inside the active Vissim instance, using Python, VBS, or JS.
Starting Vissim 6, PTV completely refactored and redesigned Vissim, almost rebuild the software from scratch, inside out. As part of this process, more gems are added, one of such, is the so-called “event-based” COM scripting. “Event-based” COM scripting is a use case of in-process COM; it was added since Vissim v7.
Once again, with the In-Menu COM/Event-based Scripting, and many other new designs/architectures, Vissim has set up a solid foundation significantly better than its v5 and any earlier generations, making itself readily primed for the future. A big congratulation is due to the PTV development team for this achievement, seriously.
As of today, Vissim 7-09 appears as the most impressive redemption of a legacy software (I mean, particularly, Vissim v4 and earlier versions) – and presents itself, with so many improvements and beef-ups, and as a powerful, sleek and increasingly popular tool for its users that have been yelling and crying for years while its competitors eating up its market share.
Aside from COM interface, Vissim also provides various APIs e.g., Signal Control API, Emission API, External Driver API etc. These APIs have to be compiled in DLL to be loaded by Vissim host, which calls back the exported functions when certain events fire.
It is interesting that “event-based” COM scripting is capable of providing a unified interface for all the above APIs. In future, it is possible that PTV might gradually phase out all these DLL-based APIs so everything is done through a unified event-based COM scripting. Granted, that is just my personal perspective.
Now, coming back to the million dollar question – can we access COM interface from inside an API DLL? For example, from inside External Driver DLL, how can we access some, if not all of the COM functions?
The answer is: yes, that is doable, but with some twist.
Now you start to have a faint of heart, aren’t you? Before we roll up our sleeves and jump to the 1-2-3 steps, I want you to take a look at the following snapshots – they are the key to the solution.
The following are the 58 exported functions from comsrv.dll, which is located in Vissim installation Exe folder. Most of these exported functions, are class methods of several classes, primarily:
💡 comsrv.dll is the “hub” of all Vissim COM functionality.
With the above in mind, let me lead you to the interesting journey to figure out comsvr.dll and Vissim COM invocation flow, till we reach the final solution to the original question.
(to be continued)
This post has already been read 2757 times!