Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement global VB6 error handler?

The global VB6 error handler product referred to in the following link claims to "install a small callback hook into the VBE6 debugger":

http://www.everythingaccess.com/simplyvba/globalerrorhandler/howitworks.htm

I would like to implement this product myself because I would like more control over what it is doing. How is the above product likely to be achieving what it does?

like image 267
CJ7 Avatar asked Mar 10 '26 09:03

CJ7


1 Answers

The product you are looking at is a COM component. From the documentation that is available on the web site, it sounds like the COM component implements particular component classes. The first thing to do, if you already have the product, would be to fire up SysInternals procmon, run regsvr32 on the DLL, and figure out what component classes are implemented from the registry entries that are created. Once you know this, MSDN may be able to tell you what interfaces correspond to those component classes.

Microsoft developed a framework called Active Scripting that allows you to host a script engine and inject debugging capabilities. If one assumes that VB6 produces an exe that ties into that framework, you might be able to do:

  • Create a COM component that implements IApplicationDebugger
  • Implement IApplicationDebugger::onHandleBreakPoint to be able to respond to errors in the VB code
  • Read MSDN KB Q222966 to find out how to call back to VB from onHandleBreakPoint

It looks like the product injects the ErrEx class using IActiveScript::AddNamedItem. To provide the same behaviour, Implement IActiveScriptSite::GetItemInfo on the same COM component to return a pointer to an instance of (and the associated TypeInfo for) a COM component that implements the same interface as ErrEx. In your implementation of ErrEx.EnableGlobalErrorHandler you would do the following:

  • CoCreateInstance inproc Process Debug Manager
  • Cast reference to IRemoteDebugApplication
  • Register an instance of your IApplicationDebugger component using IRemoteDebugApplication::ConnectDebugger

I glossed over calling IActiveScript::AddNamedItem because I have no idea how you get a pointer to IActiveScript from a running process. Also, I don't know if creating a new instance of the Process Debug Manager will work, or if you somehow have to hook into an existing instance.

I apologize for the confusing explanation, missing information, and glossing over large parts of the process, but this is going waaay back...

You will want to read the Active Scripting APIs article at MSDN.

like image 141
iboisver Avatar answered Mar 12 '26 03:03

iboisver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!