We can create any external application which produces exe
output. This application needs to be implemented such that it should reference
the DLL file and call the library function. For example, I am going to create a
Open Visual Studio 2005 IDE and create a new console application project as mentioned below:
File >> New >> Project
Project types: Visual Basic
Visual Studio installed templates: Console
Project Name: CallDLL
Open the solution explorer. You
will see a default module Module1.vb exists there.
Open Module1.vb and add code in the procedure Main() as given below:
Listing 3 – Procedure Main in Module1.vb of CallDLL
Dim oCLibrary As New DLLProject.CLibrary
Add reference of DLLProjects.dll
which exists in …\DLLProject\bin\Debug created in the
DLLProject before. Now press Ctrl+Shift+B
to build the solution containing CallDLL
project. After a successful build, CallDLL.exe file of
the project should be created in …\CallDLL\bin\Debug
folder. Note the full path of the exe. Close the CallDLL project.
Configure the library project (DLLProject) to use
caller application (CallDLL)
Open the previously created DLLProject
in Visual Studio 2005 IDE. Delete Module1.vb from the
project as we do not need it now. Open the Property
Pages of the project from the "Project"
Figure 4 –Open property page of the DLLProject
In the Property Page screen choose tab option Debug. Under the Start Action, choose
the option Start External Program. In the text box
specify the full path of caller exe (CallDLL.exe)
file. You can also use the browse button to locate the exe file.
Figure 5 – Setting start action in property page of
Close the Property Page screen and save the DLLProject.
Test the DLL project execution
Build DLLProject and press F5 to run it. After running it you will see a console
screen as the one below.
Figure 6 – Output console screen of the CallDLL.exe
run from DLLProject
Note that after running the DLLProject
we are actually getting the same results as if we had run the caller
application (CallDLL). Wait! We have not done the
debugging of the DLLProject yet by stepping into the code which is our main
purpose. We need to step into the code as we cannot always determine the
correctness of logic implemented in the DLL by just looking the output screen.
In the real world scenario we used to have very complex logic inside DLL and
multiple applications may share the DLL. Hence, a developer needs to DEBUG CODE
LINE BY LINE before releasing a DLL in production.
To set BREAKPOINT in the DLLProject code
To step into the code of DLLProject
for debugging, set the breakpoint in the implemented
function GetWelcomeMessage of DLLProject
which is being invoked by the calling application (CallDLL).
Figure 7 – Set breakpoint in the function
definition of DLLProject
Press F5 to run DLLProject. Now the execution pointer must stop at the line
which is set with breakpoint as shown below.
Figure 8 – Execution pointer hits the breakpoint
and steps into the code
Execution pointer steps into the code when breakpoint is
hit. Now you have the control of the execution for DLLProject.
Now you can debug the action of each line before deploying a release version of
DLL on production machine. Please remember that external
application EXE should always build with the updated version of the DLL to step
into the DLLProject code.