Chris D
Chris D

Reputation: 371

VS2010 - Debug win32 console application using cmd.exe

I am new to C programming and I'm currently developing a simple Win32 console application to help me learn. I'm doing this at work and they have provided me with Visual Studio 2010. Our work computers are restricted so I do not have the option to install additional software or make changes which require admin access.

While attempting to debug my program, I discovered that there are several options available. The two below are the ones I want to use:

  1. Start Debugging
  2. Start Without Debugging

When I pick option 1, the application is launched directly (as if I'd double clicked the .exe file). However, when I pick option 2, the application is launched indirectly via cmd.exe. Also, at the point where the application would normally terminate, a line of text comes up which says 'Press any key to continue'. That keeps the console open until I press another key.

Is there a way to to modify the settings in Visual Studio so that option 1 behaves the same as option 2 but still allows debugging? If not, are there any other workarounds which will accomplish the same thing and can be initiated with a single keyboard shortcut?

Upvotes: 1

Views: 370

Answers (1)

mvidelgauz
mvidelgauz

Reputation: 2214

Unfortunatelly, I don't know any "out-of-the-box" (see alternative below) way to accomplish the same thing with a single keybard command but the following is what I think could be help you:

  1. Add a call to MessageBox or _getch or something else to your code to pause execution at this point until user clicks a button or presses a key
  2. Start your application using 2nd method ("Without Debugging")
  3. When you see message box or user input prompt created in step 1 DO NOT continue yet
  4. In Visual Studio under menu "Debug" invoke "Attach to process...".
  5. In the list of currently running processes find your application. You can recognize it by message box title or user prompt or by process ID. Select that process and click "Attach" button
  6. After you will see that VS is attached to that process switch to application (cmd window) and click button or press a key to continue execution. From that point your application is running under debugger

If you really need a single command to do all this I think you'll need to write your own VS macro. If you need help with such macro it is probaly needs to be a different question.

[EDIT]

You said in your question that you are with VS2010, so the following is probably not an option for you, but just in case I'll add it here: If you were using VS2013 or (2015) you could use Child Process Debugging Power Tool (another link), which will allow you to specify cmd $(TargetPath) as "command" and then use your 1st option to debug cmd together with its child process, which will happen to be your process (screenshot from VS2012, but the same option exsists in VS versions)

enter image description here

Upvotes: 1

Related Questions