How to detect if VB6 APP is running within the IDE
Is there a way to detect at run time if my VB6 application is running within the VB6 IDE/debugger?
May not be the most elegant way, but it works:
I agree with Michael's method but I always used div by zero instead, it makes it more explicit:
Matthew, I don't code in VB any more, but thanks anyway. I was on that list years ago, though. I had a large programmer's mailing list of my own at the time, too.
How about finding out the window class of the IDE (hint: it's "wndclass_desked_gsk") and then esting the result of the FindWindow API call?
I don't think that would always work. FindWindow finds any window that matches the class name and window name specified. Therefore it would match if you were running the project outside the IDE (eg: it's an ActiveX DLL being run as part of another app) whilst looking at the project's source code, giving you a false positive.
I take your point. It's probably simpler and easier just to use the conditional define. I know that in Delphi the recommended approach is the FindWindow one which was why I suggested it.
Thanks for all the answers, humour, and critism! The debug.assert err test method satisfies my needs for now.
The Debug.Assert is the mentioned in most VB FAQs, and is what I'd probably use if I ever needed it. If I can't run a VB project in the IDE I just compile it with symbolic debug info turned on and debug it in C++ instead.
Not sure it is the best but i use.
Fog Creek Home