Yes, you can do this with Visual Studio. You have two options:
Configure your project to start the external program
Open your DLL project.
On the properties for the project, go to the Debug tab.
Choose Start external program and give the path of the external program that will call your DLL, along with any command-line arguments you may need to supply, and the working directory if that's relevant.
Save the project.
Set breakpoints in your code where you want them.
Press F5 to start debugging. (At this point, your breakpoints will say that they won't be hit because the symbols aren't loaded. Don't worry about that for now.)
Do whatever you do to make the external application load your library and run your code.
Visual Studio will detect the module load, load the symbols, and stop on the breakpoint.
Attach to an existing process
If you can't start the process but instead have to attach to a process that's already running, you can do that too:
(Side note: If you're using the "Express" edition of Visual Studio, I don't think it has this feature, but I'm not certain about that. It's easy enough to tell: You'll either have the menu item mentioned on Step 4 below or not.)
Make sure the process is running.
Open your DLL project.
Set your breakpoints, etc.
From the Debug menu, choose Attach to process...
In the resulting dialog box, find the process in the list, highlight it, and click Attach.
Visual Studio will go into debug mode. (At this point, your breakpoints will say that they won't be hit because the symbols aren't loaded. Don't worry about that for now.)
Do whatever you do to make the external process load and run your code.
Visual Studio will detect the module load in the external process, load your symbols, and stop on your breakpoint.
N.B. In both cases, if the external process loads your DLL from somewhere other than the bin/Debug
folder of your project, you must make sure you copy the DLL to that other location every time you build it (you can set that up to happen automatically in the project options). Otherwise, Visual Studio won't be able to detect that the DLL being loaded is the one you're trying to debug.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…