Intercept VB6 Button Click Event with Detours

914 views Asked by At

I want to inject my own DLL into a VB6 process, to override the default click behavior of a button. The goal, to call my method, and never call the orig VB6 code in the click event handler.

It appears the Microsoft Detours API can help. The samples show me how-to inject my DLL, into the running process; but I'm not sure the function I should be detouring.

Idealy, I would love a .Net wrapper for the Detours API.

Any help would be appreciated.

2

There are 2 answers

1
Joe Jordan On

No need to use Detours for this task, check out: Subclass External Programs done for you

This C++/ActiveX solution will allow you to subclass windows outside your current process in VB6. I am less familiar with .NET, but I do know that the commercial solution Desaware SpyWorks for .NET also provides this functionality. Do your homework first, there's probably a free solution out there, and if so post back and let us know. :)

0
rskar On

If its a way to affect all buttons at once, then I think this is going to be original reseach for you to do; I don't think anybody else has ever felt the need to circumvent the VB runtime to this degree. Otherwise, if it's just a particular button or form, subclassing is the tried-and-true way to go.

For advanced VB6 info, check out Karl Peterson's Classic VB site:

http://vb.mvps.org/samples/

Hosted on that site is Bruce McKinney's excellent book "Hardcore Visual Basic":

http://vb.mvps.org/hcvb.asp