title: How can I run Visual Basic code in a running Visual Basic 6.0 process (e.g. MSVBVM60.DLL)?
body: <p>I'm working on debugging a legacy Visual Basic 6.0 application; the application was built into native code, but unfortunately we just have the binaries, but no source code. So I'm rather limited as far as modifications to the program go.</p>
  
  <p>My final goal is to get the value of the 'Name' property of some controls given their HWND. I can easily write VisualBasic code to do this, but unfortunately I don't see how to execute this code in the context of the running application.</p>
  
  <p>My first attempt was to create an ActiveX DLL in VisualBasic which exposes my 'controlNameForHWND' function. At runtime, I then had a little utility injected a second helper DLL into the VB running process, and that helper DLL then called <a href="http://msdn.microsoft.com/en-us/library/ms686615(VS.85).aspx" rel="nofollow">CoCreateInstance</a> so that my ActiveX control (which features the 'controlNameForHWND' function I wrote in VB) is instantiated inside the process of the application.</p>
  
  <p>This worked well, but unfortunately the ActiveX control is apparently not executed in the same context as the application to be debugged. For instance, the global <code>App.hInstance</code> value is different, the array returned by the global <code>Forms</code> array is always empty, and so on. So all my VisualBasic script code is running in a parallel universe. Bad luck. :-/</p>
  
  <p>Does anybody else have ideas how to be able to "inject" VisualBasic code into a VB6 process? Looking at the process using <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653" rel="nofollow">Process Explorer</a> shows that the library <code>MSVBVM60.DLL</code> is loaded (the Microsoft Visual Basic Virtual Machine), but not e.g. <code>VBA.DLL</code>. The latter would be interesting since it exports an undocumented <code>EbExecuteLine</code> function to execute script statements.</p>
  
  <p>I'm running a bit low on ideas, so I'm grateful for the craziest ideas, too. :-)</p>