In Visual Studio 2010 we can easily create .dll and .lib files by the following steps
Open a New Project in Visual Studio.
Select the Configuration to Active Release mode in order to make your dll file safer from the outer world interference and set platform to the Win32 if your OS is of 32 bits if not edit it to "x64" for 64 bit OS.
After configuration of the properties goto C/C++ option there in change the Calling Convention to _stdcall(/Gz) (standard calling convention)
Add a new Item in the format of .cpp or create a .cpp file in which we would be calling our dll and lib files.
Now we have created our .cpp file but before going towards the coding you have to set some changes in your file properties as we have done earlier for dll file. Similarly go to the properties of the file.
Now go to general option, in linker, there in edit and browse the additional library direction and add the release folder in it.
Here you create a new line for giving the path of the release folder consisting of your library file as well as dll file.
Now you can write your program and can call your function using the dll and lib files. Here is a sample program for you. Remember here that you should mention the yellow part in your program before calling your function stored in the library.
#include<stdio.h>
#include<conio.h>
extern "C" int
_stdcall sub(int, int);
void main()
{
int c= sub(13,4);
printf("%d",c);
_getch();
}
Now if you run your program, you may get an error. This is because the .dll and .lib extention files which you have called up in your settings and in your program too, doesn't exists in the path directory of the program, so just copy the files (only .dll and .lib) from the release (or debug) folder of the dll folder and paste it to the place where your .exe file of the program had been generated.
Below are my .dll and .lib files.
And this the path where my .exe file has been generated and as you can see I have pasted my .dll and .lib files here only.
Open a New Project in Visual Studio.
In installed templates see for the Visual C++ and then for the Win32 Console Application as shown in the figure below and give it a name.
Click on Next and then click on DLL and Export Symbol as shown below.
Now you have created a dll file now you have to input the program but before that there must be some settings in your dll file. Lets have looks on those settings.
Go to the properties of the file
Then to the Configuration Properties and in that Configuration manager.
Select the Configuration to Active Release mode in order to make your dll file safer from the outer world interference and set platform to the Win32 if your OS is of 32 bits if not edit it to "x64" for 64 bit OS.
After configuration of the properties goto C/C++ option there in change the Calling Convention to _stdcall(/Gz) (standard calling convention)
Write the following code to the dll file:
extern "C" _declspec(dllexport) int
_stdcall funcName(parameters)
{
return func;
}
Now close your visual studio and again open it or simply open a new visual studio with a new project but this time project should be empty project.
Add a new Item in the format of .cpp or create a .cpp file in which we would be calling our dll and lib files.
Now we have created our .cpp file but before going towards the coding you have to set some changes in your file properties as we have done earlier for dll file. Similarly go to the properties of the file.
Here in configuration manager change the solution to Release if your dll file is in release mode and also change your active solution platform to Win32 if your OS is of 32 bit.
Now go to general option, in linker, there in edit and browse the additional library direction and add the release folder in it.
Here you create a new line for giving the path of the release folder consisting of your library file as well as dll file.
Now go to Input option, in same linker option, and there you type your library file name with .lib extension along with other library files.
Now you can write your program and can call your function using the dll and lib files. Here is a sample program for you. Remember here that you should mention the yellow part in your program before calling your function stored in the library.
#include<stdio.h>
#include<conio.h>
extern "C" int
_stdcall sub(int, int);
void main()
{
int c= sub(13,4);
printf("%d",c);
_getch();
}
Now if you run your program, you may get an error. This is because the .dll and .lib extention files which you have called up in your settings and in your program too, doesn't exists in the path directory of the program, so just copy the files (only .dll and .lib) from the release (or debug) folder of the dll folder and paste it to the place where your .exe file of the program had been generated.
Below are my .dll and .lib files.
And this the path where my .exe file has been generated and as you can see I have pasted my .dll and .lib files here only.
Now you may Run your program easily and without any bugs in it.


































