As Salem and gasingh said you find a lot of books about dlls and there is a little bit complex process depending on what you want. But, because you insist , here is a very simple example that I did for you using C++ Microsoft Dev Studio.
-Open VC++ Dev Studio
-Files->New->Projects tab -> Select Win 32 Dynamic Link Library; Choose a project name ;Let say ParseString ;Click Ok;
-Step 1 of 1 -> Check An empty DLL project->Finish->Ok
At this time you have an empty project created \ParseString folder and there some project files such as: ParseString.dsp and ParseString.dsw
Add files to the ParseString project:
1. File->New -> Files-> Select C/C++ Header File (Make sure Add to project check box in on and the project name is there) ->Type ParseString in the Filename->Click Ok
Paste there the following code (ParseString.h):
#ifndef __PARSESTRING_H
#define __PARSESTRING_H
#ifndef __PARSESTRING__
#define __PARSESTRINGLIB__ __declspec(dllimport)
#else
#define __PARSESTRINGLIB__ __declspec(dllexport)
#endif
__PARSESTRINGLIB__ char * ParseString( char *, char *, char *,int, int );
#endif
2. File->New -> Files-> Select C/C++ Source File (Make sure Add to project check box in on and the project name is there) ->Type ParseString in the Filename->Click Ok
Paste there the following code (ParseString.cpp):
#include <afx.h>
#define __PARSESTRING__
#include "PARSESTRING.h"
__PARSESTRINGLIB__ char * ParseString( char * str, char * Ldelim, char * Rdelim, int Number, int Action )
{
// Add your code here
return str;
}
Now , if you explore the project you will see the ParseString.h and ParseString.cpp files created in the \ParseString folder
3. Now build the "parsestring.dll" file :
From main menu select : Build->ParseString.dll or F7
You should have no errors and the result are two important files : \ParseString\debug\parsestring.lib
and \ParseString\debug\parsestring.dll
4. Close project: File->Close Workspace
How to test the parsestring.dll ?
1. File->New->Projects tab->Win32 Console application-> Type a project name; Let say TestParseString
--Step 1 of 1 -> Check An empty project->Finish->Ok
At this time you have an empty project created \TestParseString folder and there some project files such as: TestParseString.dsp and TestParseString.dsw
2. Add files to the TestParseString project:
File->New -> Files-> Select C/C++ Source File (Make sure Add to project check box in on and the project name is there) ->Type TestParseString in the Filename->Click Ok
Paste there the following code (TestParseString.cpp):
#include <iostream.h>
#include "parsestring.h"
int main()
{
cout << ParseString("George", "","",0,0)<< endl ;
return 0;
}
3. Build the TestParseString.exe : Build->TestParseString.exe . You cannot link.
Copy the ParseString.h and ParseString.lib files in the \TestParseString folder
Now the TestParseString project should compile and link
The results is \TestParseString\debug\testparsestring.exe file created
4. Try to run it: Build-> Execute TestParseString.exe or CTRL+F5
You will get error about parsestring.dll file.
5. Copy parsestring.dll file into the \TestParseString\debug\ folder
6. Run TestParseString.exe . It should display "George" on the console screen.
-obislavu-