Hi,
Post by Johan StäckHello!
A fairly common requirement is to detect if your VB6 code is running
compiled or in the IDE.
I use this frequently.
However, I want to take it a step further, and detect (when in the IDE)
if the program is "running free" or being "single-stepped" (using F8).
I wonder if/how this can be done.
It can be done using the undocumented EbMode function in the vba*.dll:
Private Declare Function EbMode Lib "vba5" () As Long 'vb5 ide
Private Declare Function EbMode Lib "vba6" () As Long 'vb6 ide
EbMode returns 1 if a programming is running and 2 if the program has
been halted (is in break mode).
But that alone does not help as, when it is called from VB code, even
when single stepping, in the moment it is called the function returns 1
because then the program is running.
So it must be called from the "outside", that is not from the program
under test but eg from windows itself. One way would be to use Paul
Catons API-Timer class. This class uses an assembler thunk for the timer
callback. In this thunk EbMode is called and, if 2 is returned, the
method to notificate in the program is not called. One would have to
modify this to just setting some memory location, reachable for the
program, to the last result of the EbMode call.
Assume a global variable in a module is used, named say "gMode". Then in
your code all calls to the traceing routines would have been needed to
rewritten like such:
If gMode = 1 Then Trace
However this is not a bullet proof method. Eg if by "stepping over" a
greater portion of code is run and in the meantime the timer fires, it
would set gMode to 1 and all remaining code to execute would see this mode.
BTW, there is a simple method for detecting if in IDE running, which
works also when it is embedded in a dll:
Private Declare Function GetModuleHandleA Lib "kernel32" _
(ByVal lpModuleName As String) As Long
Private Function InIde6() As Boolean
InIde = (GetModuleHandle("vba6") <> 0)
End Function
Private Function InIde5() As Boolean
InIde = (GetModuleHandle("vba5") <> 0)
End Function
:-)
--
Ulrich Korndoerfer
VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
-----------------------------------------------------------------------
Plea for a bright future for VB classic.
Sign the petition to Microsoft: -> http://classicvb.org/petition/
-----------------------------------------------------------------------