Ways to Debug the DLL
Each of the projects in this section creates a DLL. You cannot run a DLL directly; it must be called by an application, usually an EXE. For more information, see Creating and Managing Visual C++ Projects. The calling application might fit any one of the following criteria:
An application built in another project in the same Visual Studio solution that contains the class library.
An existing application already deployed on a test or production computer.
Located on the Web and accessed through a URL.
A Web application that contains a Web page which embeds the DLL.
Debugging the Calling Application
To debug a DLL, start by debugging the calling application, typically either an EXE or a Web application. There are several ways to debug it.
If you have a project for the calling application, you can open that project and start execution from the Debug menu. For more information, see b0fe0ce5-900e-421f-a4c6-aa44ddae453c.
If the calling application is an existing program already deployed on a test or production computer and is already running you can attach to it. Use this method if the DLL is a control hosted by Internet Explorer, or a control on a Web page. For more information, see 636d0a52-4bfd-48d2-89ad-d7b9ca4dc4f4.
You can debug it from the DLL project. For more information, see How to: Debug from a DLL Project.
You can debug it from the Visual Studio Immediate window. In this case, the Immediate window plays the role of the application.
Before you start debugging the calling application, you will usually want to set a breakpoint in the class library. For more information, see fe4eedc1-71aa-4928-962f-0912c334d583. When the breakpoint is hit, you can step through the code, observing the action at each line, until you isolate the problem. For more information, see 8791dac9-64d1-4bb9-b59e-8d59af1833f9.
Controls on a Web Page
To debug a Web page control, create an ASP.NET page that embeds it if such a page does not already exist. You then place breakpoints in the Web page code as well as the control code. You then invoke the Web page from Visual Studio.
Before you start debugging the calling application, you will usually want to set a breakpoint in the DLL. When the breakpoint is hit, you can step through the code, observing the action at each line, until you isolate the problem. For more information, see FE4EEDC1-71AA-4928-962F-0912C334D583.
The Immediate Window
You can evaluate functions or methods in the DLL without having a calling application. You do design-time debugging and you use the Immediate window. To debug in this manner, do the follow these steps while the DLL project is open:
Open the Debugger Immediate window.
To test a method named Test in class Class1, instantiate an object of type Class1 by typing the following C# code in the Immediate window. This managed code works for Visual Basic and C++, with appropriate syntax changes:
Class1 obj = new Class1();
In C#, all names must be fully qualified. In addition, any methods or variables must be in the current scope and context of the debugging session.
Assuming that Test takes one int parameter, evaluate Test using the Immediate window:
?obj.Test(10)
The result will be printed in the Immediate window.
You can continue to debug Test by placing a breakpoint inside it and then evaluating the function again:
?obj.Test(10);
The breakpoint will be hit and you will be able to step through Test. After execution has left Test, the Debugger will be back in Design mode.
For more information please visit Debugging DLL Projects.