Microsoft has a lot of header files, which define a number of functions, but in the header file you can not find the function content of the figure, because the function body is saved in the Lib library. One of the benefits of saving in the library is that the source code is not easily discoverable, which means that some of these techniques are not easy to learn. Talk less, we start making Lib library now.
First, the first step, open vc++6.0, press CTRL + N, select the Project tab, select the "Win32 Static Library" option, enter the project name, we here with "Lib Library", we can choose their own, as for the path, choose a bar, anyway, this is just LIB experiment.
Then click "OK", we do not choose two, if you choose "Precompiled Header File" then the system will automatically help you build stdafx.h and stdafx.cpp. But another "MFC support" I haven't tried.
Click Finish to create an empty project, we create a new CPP file (Note the "Add to the project" Lib Library "this option, enter the file name Main.cpp, followed by the Main.cpp the middle Input function code and header file, note that there is no need to add a main function or similar functions including the DllMain function.
Compile, wrong error, correct operation. VC6 will prompt for the executable file name, we click Cancel, then generate Lib library. Lib complete.
Now, please copy the Lib Library. Lib under debug to the system directory or the D drive (I copied to the D drive)
Don't think it's done now! We create a new. h file (you can actually open any folder or drive, right-click New Text Document, and then rename the. h file.) Here with Lib.h, use Notepad or vc++6 to open our newly created. h file, copy the prototype of the function in your definition, for example, I just defined a function in the Lib file:
int ABC () { printf ("abc\n"); return 0 ;}
So I'll just write this in my header file: "int abc ();" (quotation marks are not counted), note that there is a semicolon behind it. After you edit the file, you can quote it. Copy the. h file to the D drive, create a new CPP file in the VC6, and enter (I have the Lib file and the. h file here to do the demonstration under D:\):
#include <d:\lib.h>#pragma comment (lib, "D:\lib.lib") // not # include, I wrote the diary at the beginning of the wrong, thank the hurricane for me from the sky to point out the int main () { abc (); return 0 ;}
Run, no errors, you will see the screen output ABC. What do you think? It is also necessary to note that although the DLL can also implement this same function, but Lib has the following advantages (contrast DLL):
1. No DllMain function, easy to run
2. Small size
3. After running Lib is embedded in the program, the DLL will be next to the program with a small tail (DLL file)
"vc++6.0" successfully produced and used Lib library, reprinted