Showing posts with label Clever. Show all posts
Showing posts with label Clever. Show all posts

Wednesday, 17 January 2018

VBA - Equivalent of Spy++ - thanks to Mark Rowlinson

Sometimes, a VBA developer must break out if the VBA sandbox and resort to calling the Windows API directly; in these cases it is often to manipulate or interact with a window for which the developer needs to acquire the window's handle. A good program to investigate the structure and hierarchy of windows of an application is Spy++ (SpyXX.Exe) which dates back Visual Studio 6.0. Here is a screenshot showing the Excel windows and there are many.

Thanks to a clever guy called Mark Rowlinson there is some clever code which replicates the output of Spy++. The code is over at VBA Express. Here is a screenshot of the Excel windows details.

Tuesday, 2 May 2017

DispCallFunc opens a new door to COM interfaces and VBA Function Pointers

So during my research on Type Information it seems that Dispatch carries with it some amazing type querying functionality. Not only that it seems IDispatch and Type Libraries interrogation interfaces are pretty much the same

I always knew IDispatch had to do some work but looking into it seems both amazing and fascinating. Also, it seems that there are some COM system functions that act as low level helpers, one such function is DispCallFunc found in oleaut32.dll.

A clever man called Krivous Anatolii Anatolevich has used this to allow VBA programmers call into IClassFactory::CreateInstance; a problem I solved only with resort to C++/VBA hybrid code. Lots of interesting stuff there at his GitHub page.

Another clever man Mikael Katajamäki has discovered how to use DispCallFunc to form part of a solution for a recursive mathematical root finder. His code is over at Windows API DispCallFunc as function pointer in VBA

Whilst VBA already has AddressOf and Application.OnTime, often it is required to pass parameters to a callback function. DispCallFunc may give the solution to that problem instance.

This idea is debated in an excellent thread discussion over at vbforums.com

As a footnote and coda and not related to DispCallFunc is an incredible project that writes assembly code into memory before calling it. This can be found at wonderful website called FreeVBcode.com to which I shall be returning. The said code is found at Call API functions by Name, without Declare, v 2.0