Visual Studio 2010 - Debug DLL - Debug Command using rundll32 doesn't work - visual-studio-2010

I have a problem debugging a C++ DLL project in Visual Studio 2010. While debuging I want the DLL to be loaded by rundll32.exe automatically. To do so I follow these steps (like here http://msdn.microsoft.com/en-us/library/c91k1xcf.aspx):
In Solution Explorer, I select the project that creates the DLL.
From the View menu, I choose Property Pages.
In the Property Pages dialog box, I open the Configuration Properties folder and select the Debugging category.
In the Command box, I type: "C:\Windows\System32\rundll32.exe"
In the Command Arguments box I type (main is the function to be executed): output.dll, main
In the Working Directory I type: $(SolutionDir)$(Configuration)
Attach -> yes
After following these steps, I try to debug the DLL, but I get this error:
"Unable to attach. Process "C:/Windows/System32\rundll32.exe" is not running on "MY-PC", Refresh the process list before attempting another attach."
Anyone know how to debug a DLL, without manually starting rundll32.exe from command prompt and manually attaching to this process?

You should set:
"Attach -> no"
otherwise the VS is not trying to start new rundll32.exe process.
Setting Attach -> yes tells VS to attach to existing process.

Related

how to run the NetOffice example?

I'm checking NetOffice and trying to run a simple example from below:
https://github.com/NetOfficeFw/Samples/tree/master/Excel/02%20NetOffice%20Excel%20COMAddin%20Sample/01%20Simple
how can run this example in visual studio? ideally I think it should be opening a blank Excel which contains addin, but when debugging, it just an error "In order to debug this project , add an executable project to this solution...."
so what executable project I need to add?
thanks,
To debug this example, you must do two steps:
The add-in must be registered in the registry to load it when starting Excel.
This step is done automatically, when you built the add-in (this is part of the NetOffice "magic" with the COMAddin attribute).
You can do the registration of the add-in manually too by using regasm.exe.
Excel must be started so that the add-in is loaded and the debugger can be used.
I prefer to set this up in the project properties. Go in the project properties on the tab Debug, go on Start external program and select the path of the excel.exe on your computer.
You could also start Excel and attach the project debugging to the Excel process.
If you have done the two steps, then start debugging by clicking F5. Now Excel starts. If you set a breakpoint, then it should be reached either at the Excel starting process or when you open a workbook in Excel.

What do I do to run Windbg/dbeng.dll commands from within the Visual Studio debugger and the Immediate Window?

I saw in a video talk by Bart de Smet where he was running Windbg commands by typing them into the Immediate Window in Visual Studio when running the project in debug mode inside the Visual Studio debugger.
So, I wanted to try that myself. So here's what I did:
I went to the Project Properties dialog and then selected the Debug tab, then checked the Enable native code debugging in the Enable Debuggers section.
I set a breakpoint on one of the lines and then launched the project with debugging by hitting F5. When the breakpoint was hit, I opened the Immediate Window and typed the .load command to load sos.dll.
But the message I got as a result read:
.load "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\sos.dll"
error CS1525: Invalid expression term '.'
Is there something else I need to do?
I am using Visual Studio 2015 Community edition.
Run your application without debugging
Choose Debug/attach to process ...
Choose "Windows User Mode Debugger" as transport
Click "Refresh"
Choose your application
Click "Attach"
Open the "Immediate Window", which will labelled be "Debugger Immediate Window"
Enter WinDbg commands

VS Debugging: Attach to a process that hasn't startet

In Visual Studio I can attach the debugger to any process that is currently running.
I have an application that is calling my DLLs and what I need is to debug this process from it's beginning. Is this possible?
Open the project properties (context menu, Properties or Alt+Enter)
Go to the Debug tab
Choose "Start external program"
Save and close
Choose debug mode
Run the application (F5)
If the application expects the DLL in a specific path, it may be necessary to add a post build step to copy the DLL to the expected location.

Debug exe in visual studio 2010

Is there a way to debug external exe using visual studio 2010 by shift+double click to run the exe. Normally, to run the application in a special mode we have press the shift and double click the exe, but I have a bug that happens right on start up and I guess I need to add a command line argument to get it into that mode. I hope this makes sense.
So basically you want to attach debugger as soon as the process starts. This should help. Source http://blogs.msdn.com/b/greggm/archive/2005/02/21/377663.aspx
Run regedit.exe
Goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options
Create a new key for your exe (example: foo.exe)
Create a new string value under your exe. The name of the string
value is 'Debugger', and the value is 'vsjitdebugger.exe'
If I understand enough of that, you want to debug a program not launched by VS.. In vs pro+ you can select "debug" and then "Attach to process" so you would start your applicaiton and then can attach to it.

I want to start VB project in Visual Studio 2010 when I am debugging the .ocx

Well, I am writing an ActiveX component in Visual Studio 2010 and using MFC wizard. When I debug the solution I want to start the actual program ( it is VS 2010) that is going to use that .ocx. In VC++ 6.0, I am able to do that by following steps:
1) Click Project in menubar
2) Select settings in the drop menu
3) Select the debug tab: With Category as General I put the path of VB.exe in box for executable during debug session and in program arguments I would write the path of VB project that uses the said .ocx.
I would like to do same thing, for MFC wizard in Visual Studio 2010. How to do it?
If you right-click on the ActiveX project, select 'Properties', then under 'Configuration properties|Debugging' you can set the name of the executable to start ('Command') and its command-line arguments ('Command Arguments').
You should select the EXE of you VB host program (I am not 100% sure what is the program you need to start)
An alternative is to start the program that uses the OCX and then attach the debugger to it: select 'Debug|Attach to process...' in the main menu, and then select the process in the dialog.

Resources