To debug the library functions using immediate window, we
can follow any of the following ways:
By implementing procedure Main() which calls the library function.
By making the library function Shared.
by implementing Main() in module to call the library
In the DLLProject press CTRL+Shift+A to open Add New Item
window. Choose Module and let the name be Module1.vb.
Add the code given in Listing 2 in the Module1.vb.
Listing 2 – Implement Main() in Module1.vb to call the
Dim oCLibrary As New CLibrary
function is implemented to call the library function GetWelcomeMessage
by passing required parameters. Now we can set breakpoint at any line in the
definition of Main() or GetWelcomeMessage and use
immediate windows to step into the code as we do in any other windows or
Say I put the breakpoint at function GetWelcomeMessage
as given in the figure below.
Figure 1 – Setting breakpoint in the library
Now open the immediate window by pressing CTRL+ALT+I or
using Debug >> Window >> Immediate. Write Main() or ? Main() in the window and
press the Enter key. You will see that breakpoint is hit by the execution
pointer and now you can debug the function.
Figure 2 – Executing Main() from immediate window
to step into the library function code
using Shared access-specifier to the library function.
You can directly debug the functions implemented in class
library application just by using Shared
access-specifier for the functions. In this way you do not need the module file
procedure. In the immediate window call the shared function by using the class
name. For example, to call the function GetWelcomeMessage
in the class CLibrary of the sample DLLProject, write CLibrary.GetWelcomeMessage("MyName","MyCompany")
in the immediate window and press Enter. The execution
pointer will hit the breakpoint and thereafter you can debug the function.
Figure 3 – Executing Shared function from immediate
window to step into the library function code