Answer to Question #193012 in Algorithms for Jean Claude

Question #193012

Assignment 3

Using the Windows API, write a C/C++ system program to create a DLL to delete files in the Windows file system as follows:

a)     Write the DLL header file.

b)     Write the DLL main program and compile it.

c)     Write the main program that loads the DLL at runtime.

d)     Compile and run the program, create a zip file containing the source codes (i.e. DLL header file, DLL main file and the main program file) and upload it.


1
Expert's answer
2021-05-15T14:43:35-0400

Steps to create a dll in c++:

· Open the visual studio and click on the menu bar to create a new project.

· After selecting the new project, a new dialog box will be open, here select the project type Win32 and give the name to the DLL project.

· On the Overview page of the Win32 Application Wizard dialog box, choose the Next button. After clicking the next button a new window will open. It is Application setting window here we will select the type of the application and click on the finish button to create the DLL project.

· After creating the DLL project we have to add the header files and source file as per our requirements. Here I am adding only one header file (Remove.h).

· When you have created the header file then write the desired content as per the requirements.

class REMOVE_API RemoveApi
{
public:
void Del(void);
};

· it’s time to define your class member function in the source file. Here I am defining all member functions in RemoveDll.CPP file.

#include<iostream>
#include<stdio.h>
using namespace std;
#include "stdafx.h"
#include"Remove.h"
#include<iostream>
void Remove_api::Del(void)
{
   int status;
   char fileName[20];
   cout<<"Enter the Name of File: "<<endl;
   cin>>fileName;
   status = remove(fileName);
   if(status==0)
       cout<<"\nFile Deleted Successfully!";
   else
       cout<<"\nErorr Occurred!";
   cout<<endl;
   return 0;
}

· Now source and header files are added to the DLL project, to create the DLL and lib just build the DLL project. If everything is fine and your DLL project compiles perfectly without any error then a DLL and .lib file will be generated.

Steps to create a C++ Application

· Click on the menu bar to create a new c++ Application project that uses the DLL which we have created just now.

· After selecting the new project a new dialog box will be open, here select the project type Win32 Console Application and give the name to the App project.

· On the Overview page of the Win32 Application Wizard dialog box, choose the Next button. After clicking the next button a new window will open. It is the Application setting window here we will select the type of the application and click on the finish button to create the c++ Console Application project.

· Now your C++ application project is ready to use the DLL ( Dynamic linking library).

Steps to Link DLL with c++ Application

· When we have created the DLL and Application then after that we have to reference the DLL to the Application that makes the enable to Application to use the DLL function as per the requirement.

· When you click on the Add new Reference then a dialog box will be open which has the lists of the library that you can reference. You need to just click on the check button to the required library. Here only one library is showing in the dialog box.

· Now your created library is linked with the created Application, but before using the DLL in Application you have to add the DLL header file.

· After giving the path of DLL header file you able to include the DLL header file in your application. Now it’s time to access the function of the DLL as per the requirement.

#include "stdafx.h"
#include"Remove.h"
int _tmain(_TCHAR*argv[])
{
Remove_API obj;
Obj.Del();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS