Can’t believe I hadn’t thought of this before…
More than that, I can’t believe I
can’t find _
anyone_ who hasn’t thought of this one…
Sometimes, you need to be able to grab onto an EXE before it launches with a debugger and watch everything it does for some clue of what is going wrong. I’ve been working on an interop layer from PowerBuilder to .Net via a set of unmanaged interfaces on the PB side (PBNI) and C++/CLI on the CLR side. Right before last week’s demo, the mapping application we’re building stopped working completely and unexpectedly, where the run before it was working. Turned out that it was due to me writing to the event log without a defined event source (still can’t explain why it worked in the first place). The only way I found that out is by grabbing the EXE on launch and watching where it failed, since it is a Powerbuilder app, and it doesn’t generate debug info when it creates the EXE file… and forget about using the Powerbuilder IDE to do anything. It becomes more of a basket case than the program I’m trying to debug!
The only way I knew how to do this is by
creating a new key in the HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options registry key with the name of the file, and a string value with "devenv.exe /debugexe" as the data. Everytime you launched the EXE on the system, it would bring up Visual Studio instead, and you could debug the process. This worked, but it was a pain to manage the key.
Enter "SendTo". It is a directory in your profile (C:Documents and Settings<your user name> by default). Create a shortcut there called "Visual Studio to Debug" and make it point to ‘"C:Program FilesMicrosoft Visual Studio 8Common7IDEdevenv.exe" /debugexe’. When you right click an EXE, choose this new option in the "Send To >" menu item, and Visual Studio will come up with the EXE ready to launch. Ahh… much more efficient.
Filed under: Tools