Quote Originally Posted by SearchingDataOnly View Post
if it is possible to disguise a module as a class/object to use. Because I want to use CallByName in the module, for example:
It is possible with some notices/preconditions.

Generally you can implement an equivalent of CallByName for plain procedures if you have a TLB describing these precedures. I should mention again, that TLB can not only describe COM interfaces and their methods, COM classes (co-classes) and their implemented interfaces, dispinterfaces, enums and constants, but plain modules and their members (procedures) can be described by TLB as well. Having combination of information about number and type of arguments, return type and procedure calling convertion is enough to implement a mechanism that can construct appropriate stack frame from original VARIANTs, pass executing to a procedure being called and clean-up stack afterwards.

Actually, we already have such mechanism within MSVBVM60.DLL as part of a so-called expression server. But it's major disadvantage that I discovered during reverse-engineering is that it limits itself to use only the TLB that is built into MSVBVM60.DLL itself. As a result, you can only call functions for MSVBVM: MsgBox, Beep, Abs, DoEvents, InputBox and any of others. You cannot call procedures from arbitrary executable modules (this limitation seems a bit artificial).

So you have to either implement such mechanism yourself (not so hard), or hack an existing expression server facility by applyting patches (and taking care to respect all the existing versions of MSVBVM60 and their differences).

For practical use, if you are going to call procedures not from some other DLLs (equipped with a TLB describing all public proecdures), but from your own project, in addition to implementing such mechanism you need to do two extra things:

  1. Make a TLB describing all your modules and their public procedures. You can use MIDL and compile TLBs manually, or you can make an Add-in that will construct TLBs using special CreateTypeLIb + ICreateTypeLib.
  2. Force VB to put these procedures into export table. Again, you can do it manually using those undocumented switches that I discovered ([VBCompiler] and LinkSwitches) or do it as part of your add-in.


Like it was done in my CreateInstanceByClassName, you'll likely need to make special handling for the case when your project is trying to call a procedure from the same project (or other project from the current project group) rather than from compiled executable.